Node Inventory Reports


As we can retrieve all facts, classes, and agent plugins for all nodes, we can do some custom reporting on all of these.

The mco inventory tool is a generic node and network reporting tool. It also has basic scripting abilities.

Single Node View

To obtain a full inventory for a given node you can run mco inventory <name> and receive a report about the node’s details:

$ mco inventory
Inventory for

  Server Statistics:
                  Start Time: Mon Sep 13 18:24:46 +0100 2010
                 Config File: /etc/mcollective/server.cfg
                  Process ID: 5197
              Total Messages: 62
     Messages Passed Filters: 62
           Messages Filtered: 0
                Replies Sent: 61
        Total Processor Time: 0.18 seconds
                 System Time: 0.01 seconds

      discovery       echo            nrpe
      package         process         puppetd
      rpctest         service

   Configuration Management Classes:
      aliases                        apache

      architecture => i386
      country => de
      culturemotd => 1
      customer => rip
      diskdrives => xvda

Collective List

MCollective nodes can be assigned to any number of Subcollectives, and you can use the inventory application to get an overview of all known collectives:

$ mco inventory --list-collectives

 * [ ===================================== ] 52 / 52

   Collective                     Nodes
   ==========                     =====
   za_collective                  2
   us_collective                  7
   uk_collective                  19
   de_collective                  24
   eu_collective                  45
   mcollective                    52

                     Total nodes: 52

Collective Map

You can also create a DOT format graph of your collective:

$ mco inventory --collective-graph

Retrieving collective info....
Graph of 52 nodes has been written to

The graph will be a simple dot graph that can be viewed with Graphviz, Gephi or other compatible software.

Custom Reports

You can create little scriptlets and pass them into mco inventory with the –script option.

You have the following data available to your reports:

Variable Description
time The time the report was started (normal Ruby Time object)
identity The sender id
facts A hash of facts
agents An array of agents
classes An array of CF Classes

Printf Style Reports

Say you need a report of all your IBM hardware listing hostname, serial number, and product name. You can write a scriptlet like this:

# ./
inventory do
    format "%s:\t\t%s\t\t%s"

    fields { [ identity, facts["serialnumber"], facts["productname"] ] }

Assuming you saved the file as, run the inventory application like this:

% mco inventory -W "productname=/IBM|BladeCenter/" --script
 xx12:           99xxx21         BladeCenter HS22 -[7870B3G]-
 xx9:            99xxx46         BladeCenter HS22 -[7870B3G]-
 xx10:           99xxx29         BladeCenter HS22 -[7870B3G]-
 yy1:            KDxxxFR         IBM System x3655 -[79855AY]-
 xx5:            99xxx85         IBM eServer BladeCenter HS21 -[8853GLG]-

Perl Format Style Reports

To use this you need to install the formatr gem; once that’s installed you can create a report scriptlet like below:

# ./
formatted_inventory do
    page_length 20

    page_heading <<TOP

            Node Report @<<<<<<<<<<<<<<<<<<<<<<<<<

Hostname:         Customer:     Distribution:

    page_body <<BODY

@<<<<<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
identity,    facts["customer"], facts["lsbdistdescription"]

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.

The output looks like this:

% mco inventory -W "/dev_server/" --script

            Node Report Sun Aug 01 10:30:57 +0100

Hostname:         Customer:     Distribution:
-------------------------------------------------------------------------      rip           CentOS release 5.5 (Final)
                                AMD Athlon(tm) 64 X2 Dual Core Processor      xxxxxxx       CentOS release 5.5 (Final)
                                AMD Athlon(tm) 64 X2 Dual Core Processor

Perl-style reports are a somewhat old and awkward format, but they fit well into a CLI environment and work reasonably well for simple reports. You can see the perlform man page for details of how to write reporting layouts; the Formatr gem stays pretty close to the original implementation. See Formatr’s documentation for info on any differences.

How helpful was this page?
Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.