5458cda198c66c9a936ee7e79f7a553475c96863
[packages/precise/mcollective.git] / website / reference / ui / nodereports.md
1 ---
2 layout: default
3 title: Node Reports
4 ---
5 [Subcollectives]: ../basic/subcollectives.html
6
7 As we have all facts, classes and agents for nodes we can do some custom reporting on all of these.
8
9 The _mco inventory_ tool is a generic node and network reporting tool, it has basic scripting abilities.
10
11 **Note: This is an emerging feature, the scripting language is likely to change**
12
13 ## Node View
14 To obtain a full inventory for a given node you can run _mco inventory_ like this:
15
16 {% highlight console %}
17  % mco inventory your.node.com
18  Inventory for your.node.com:
19
20
21    Server Statistics:
22                    Start Time: Mon Sep 13 18:24:46 +0100 2010
23                   Config File: /etc/mcollective/server.cfg
24                    Process ID: 5197
25                Total Messages: 62
26       Messages Passed Filters: 62
27             Messages Filtered: 0
28                  Replies Sent: 61
29          Total Processor Time: 0.18 seconds
30                   System Time: 0.01 seconds
31
32     Agents:
33        discovery       echo            nrpe
34        package         process         puppetd
35        rpctest         service
36
37     Configuration Management Classes:
38        aliases                        apache
39        <snip>
40
41     Facts:
42        architecture => i386
43        country => de
44        culturemotd => 1
45        customer => rip
46        diskdrives => xvda
47        <snip>
48 {% endhighlight %}
49
50 This gives you a good idea of all the details available for a node.
51
52 ## Collective List
53
54 We have a concept of [Subcollectives] and you can use the inventory application to get a quick
55 report on all known collectives:
56
57 {% highlight console %}
58 $ mco inventory --list-collectives
59
60  * [ ===================================== ] 52 / 52
61
62    Collective                     Nodes
63    ==========                     =====
64    za_collective                  2
65    us_collective                  7
66    uk_collective                  19
67    de_collective                  24
68    eu_collective                  45
69    mcollective                    52
70
71                      Total nodes: 52
72
73 {% endhighlight %}
74
75 ## Collective Map
76
77 You can also create a DOT format graph of your collective:
78
79 {% highlight console %}
80 $ mco inventory --collective-graph collective.dot
81
82 Retrieving collective info....
83 Graph of 52 nodes has been written to collective.dot
84 {% endhighlight %}
85
86 The graph will be a simple dot graph that can be viewed with Graphviz, Gephi or
87 other compatible software.
88
89 ## Custom Reports
90
91 You can create little scriptlets and pass them into *mco inventory* with the *--script* option.
92
93 You have the following data available to your reports:
94
95 | Variable | Description |
96 |----------|-------------|
97 |time|The time the report was started, normal Ruby Time object|
98 |identity|The sender id|
99 |facts|A hash of facts|
100 |agents|An array of agents|
101 |classes|An array of CF Classes|
102
103 ### printf style reports
104
105 Lets say you now need a report of all your IBM hardware listing hostname, serial number and product name you can write a scriptlet like this:
106
107 {% highlight ruby linenos %}
108 inventory do
109     format "%s:\t\t%s\t\t%s"
110
111     fields { [ identity, facts["serialnumber"], facts["productname"] ] }
112 end
113 {% endhighlight %}
114
115 And if saved as _inventory.mc_ run it like this:
116
117 {% highlight console %}
118  % mco inventory -W "productname=/IBM|BladeCenter/" --script inventory.mc
119  xx12:           99xxx21         BladeCenter HS22 -[7870B3G]-
120  xx9:            99xxx46         BladeCenter HS22 -[7870B3G]-
121  xx10:           99xxx29         BladeCenter HS22 -[7870B3G]-
122  yy1:            KDxxxFR         IBM System x3655 -[79855AY]-
123  xx5:            99xxx85         IBM eServer BladeCenter HS21 -[8853GLG]-
124  <snip>
125 {% endhighlight %}
126
127 We'll add more capabilities in the future, for now you can access *facts* as a hash, *agents* and *classes* as arrays as well as *identity* as a string.
128
129
130 ### Perl format style reports
131 To use this you need to install the *formatr* gem, once that's installed you can create a report scriptlet like below:
132
133 {% highlight ruby linenos %}
134 formatted_inventory do
135     page_length 20
136
137     page_heading <<TOP
138
139             Node Report @<<<<<<<<<<<<<<<<<<<<<<<<<
140                         time
141
142 Hostname:         Customer:     Distribution:
143 -------------------------------------------------------------------------
144 TOP
145
146     page_body <<BODY
147
148 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
149 identity,    facts["customer"], facts["lsbdistdescription"]
150                                 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
151                                 facts["processor0"]
152 BODY
153 end
154 {% endhighlight %}
155
156 Here we create a paged report - 20 nodes per page - with a heading section and a 2 line report per node with identity, customer, distribution and processor.
157
158 The output looks like this:
159
160 {% highlight console %}
161  % mco inventory -W "/dev_server/" --script inventory.mc
162
163              Node Report Sun Aug 01 10:30:57 +0100
164
165  Hostname:         Customer:     Distribution:
166  -------------------------------------------------------------------------
167
168  dev1.one.net      rip           CentOS release 5.5 (Final)
169                                  AMD Athlon(tm) 64 X2 Dual Core Processor
170
171  dev1.two.net      xxxxxxx       CentOS release 5.5 (Final)
172                                  AMD Athlon(tm) 64 X2 Dual Core Processor
173 {% endhighlight %}
174
175 Writing these reports are pretty ugly I freely admit, however it avoids designing our own reporting engine and it's pretty good for kicking out simple reports.  You can see the *perlform* man page for details of the reporting layouts, ours is pretty close to that thanks to Formatr