IBM Support

Interrogating ITNM Collectors & cloning an EMS (with ncp_query_collector.pl & fake_collector.pl)

Technical Blog Post


Abstract

Interrogating ITNM Collectors & cloning an EMS (with ncp_query_collector.pl & fake_collector.pl)

Body

ncp_query_collector.pl & ncp_fake_collector.pl

One useful tool mentioned briefly in the Collector Developer Guide v1.5 is ncp_query_collector.pl.
 
ncp_query_collector is a Perl based tool that allows you to issue XML-RPC calls to Java or Perl Collectors and view (and store) the response.
 
It is useful in the following scenarios;
  • Collector development; to validate your Collector without running a discovery
  • Collector discovery issue investigation; to verify what the Collector sends to the discovery Agents
  • Capturing a snapshot of a collector; to enable a discovery even when away from an target EMS
In 4.1 the tool can be found here: $NCHOME/precision/scripts/perl/scripts/ncp_query_collector.pl
It is not shipped in earlier releases, though you may find it still works with earlier collectors.
 
Use the -help command line option for usage details:

image

There are two modes of operation; interactive and walk.

Interactive Mode

To run in interactive mode run the tool specifying the port of the target Collector;
 
    ncp_perl ncp_query_collector.pl -port <collectorPort>

image

The GetXXX methods are those that ITNM uses to query the Collector for data (see the Collector Developer Guide for more information).
In interactive mode you can issue those calls as if you were the ITNM Agents/Finder.

Tip: Some collectors don't download their data on start up, so you may need to issue the UpdateData() call (usually issued by ITNM's Collector Finder) to get things loaded;

image

For example to test the Collector is up you could issue GetInfo(), which is essentially what the Collector Finder uses as a 'Collector ping' for the seeds you'd normally specify in DiscoCollectorFinderSeeds.cfg;

image

Once you've confirmed that GetInfo() works you can move on to the other calls of interest to you, e.g. GetDeviceList() etc...

Walk Mode

In a way this means you can take the EMS discovery home with you.
 
Note: This isn't a simulation/replay of the EMS (which would of course be EMS specific), it's a simulation/replay of the Collectors responses (which are based on the data it got from the EMS). 
The advantage is that this single script works with all Collectors. The disadvantage is that for issue investigation you can only use this approach to test functionality downstream from the Collector.
 
Note: As this mode was originally developed for Perl Collectors and as Java Collector are more strict when it comes to matching XML-RPC methods there are some changes that need to be made to the script if you wish to use it against Java Collectors (listed at the end). This will be addressed in a later release.
 
The walk mode is launched by specifying the additional command line option -walksource;

    ncp_perl ncp_query_collector.pl -port <collectorPort> -walksource 1

where 1 is the datasource that you want to walk: Collectors usually only have one datasource with id 1 - you can see which datasources a Collector has by looking in the GetInfo() response.
 
This will trigger the script to issue every ITNM suppported XML-RPC call against every device supported by that Collector's data source. 
The resulting responses will be formated in a form compatible with the fake_collector.pl tool and should be redirected to a file;

image

If you're trying to walk a particularly large data source then you may want to pipe the output to a compression utility before writing it to disk, e.g.
 
    ncp_perl $NCHOME/precision/scripts/perl/scripts/ncp_query_collector.pl -port 8080 -walksource 1 | gzip > CollectorSnapshot.cfg.gz
 
If you do that then you'll need to decompress the file prior to using it with fake_collector.pl.
The fake_collector.pl tool cab bve found here in 4.1+:  $NCHOME/precision/scripts/perl/scripts/fake_collector.pl
You just need to specify the ncp_query_collector.pl output and the port that you want the fake Collector to listen to ITNM on.
 
For example here we walk the Collector on port 8081, and create a fake Collector that gives the same responses on port 8089: As far as ITNM would be concerned the discovery against 8089 is the same as that against 8081, yet we can now kill the 8081 Collector, and have the advantage of not needing EMS access or having to wait for a slow EMS (at the expense of only having stale data of course);
 

image

Getting walk mode working for Java Collectors

As Java Collectors are more strict regarding XML-RPC method signatures the ncp_query_collector.pl script as it stands has trouble with GetInfo() and GetDeviceList().
Although this will be fixed in a later release here's what adventurous types would need to change to get ncp_query_collector.pl compatible here and now;

 

     - Line 466: change;
        if( ExecuteAndDumpCall( $client, "GetInfo", $sourceId ) )
       to 
        if( ExecuteAndDumpCall( $client, "GetInfo" ) )
    
     - Line 469: change;
        ExecuteAndDumpCall( $client, "GetDeviceList", $sourceId );
        to
        ExecuteAndDumpCall( $client, "GetDeviceList", $sourceId, 0, '', '' ); 
 
    - Line 537: change
            print "    },\n";
       to
            print "\n    },\n";
            
    - Line 555: add line;
        my $param4 = shift;
    
    - Line 561: change;
        if( defined $param2 )
      to
        if( defined $param2 and not defined $param4 )
    
    - Line 586: change;
        $rpcComment .= " $param1" if $param1;
        $rpcComment .= ", $param2" if $param2;
        $rpcComment .= ", $param3" if $param3;
        $rpcComment .= " ): ";
    
        print "$rpcComment";
    
        my @args;
        push( @args, $param1) if $param1;
        push( @args, $param2) if $param2;
        push( @args, $param3) if $param3;
      to
        $rpcComment .= " $param1" if defined $param1;
        $rpcComment .= ", $param2" if defined $param2;
        $rpcComment .= ", $param3" if defined $param3;
        $rpcComment .= ", $param4" if defined $param4;
        $rpcComment .= " ): ";
    
        print "$rpcComment";
    
        my @args;
        push( @args, $param1) if defined $param1;
        push( @args, $param2) if defined $param2;
        push( @args, $param3) if defined $param3;
        push( @args, $param4) if defined $param4;
     
     i.e. add two lines for $param4 and change each if to 'if defined'.

 

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"","label":""},"Component":"","Platform":[{"code":"","label":""}],"Version":"","Edition":"","Line of Business":{"code":"","label":""}}]

UID

ibm11082145