External command datasource (.xml) for Net-SNMP/UCD-SNMP

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
Ashmodai
Posts: 1
Joined: Fri Jan 23, 2004 7:48 am
Contact:

External command datasource (.xml) for Net-SNMP/UCD-SNMP

Post by Ashmodai »

Pretty simple stuff. Net-SNMP (and UCD-SNMP, for that matter, I believe) allow you to specify external commands whose output is displayed as part of the MIB tree indexed at .1.3.6.1.4.1.2021.8.1.1. Look in the manual page of 'snmpd.conf' for the "exec" command. I use this to monitor all sorts of stuff - for example, to parse the output of "tc -s -d qdisc ls dev <interface>" in order to get 64 bit counters for gigabit interfaces which cannot be graphed via the regular IF-MIB due to the tendency of the counters to overflow twice or more during the 5 minute polling interval.

net-snmp_command.xml goes in <cacti_dir>/resource/snmp_queries

You'll need to create a new a Data Query and point it to the xml file you just put there. Contents are displayed below. Once the data query is created, you can associate it with a host (Polling Hosts -> Associated Data Queries), and it will pull all of the external commands as well as their output over, allowing you to make perty graphs :)

I haven't included any data templates with this because it can be used for just about anything, but it's a starting point.

Code: Select all

<interface>
        <name>Get Data from Script Commands</name>
        <oid_index>.1.3.6.1.4.1.2021.8.1.1</oid_index>

        <fields>
                <cmdIndex>
                        <name>Index</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.1</oid>
                </cmdIndex>
                <cmdName>
                        <name>Command Name</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.2</oid>
                </cmdName>
                <Command>
                        <name>Command</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.3</oid>
                </Command>
                <cmdReturnCode>
                        <name>Return Code</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.100</oid>
                </cmdReturnCode>
                <cmdOutput>
                        <name>Output</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.101</oid>
                </cmdOutput>
                <cmdErrorCode>
                        <name>Error Code</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.102</oid>
                </cmdErrorCode>
                <cmdErrorHandler>
                        <name>Error Handler</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.2021.8.1.103</oid>
                </cmdErrorHandler>
        </fields>
</interface>


My config (snmpd.conf):

Code: Select all

....
interface eth0 6 1000000000
interface eth1 6 1000000000
exec Downloads /usr/local/sbin/getbytes 1:10
exec Website /usr/local/sbin/getbytes 1:20
exec Total /usr/local/sbin/getbytes 1:1
.....
And the output of walking that MIB tree:

Code: Select all

.1.3.6.1.4.1.2021.8.1.1.1 = INTEGER: 1
.1.3.6.1.4.1.2021.8.1.1.2 = INTEGER: 2
.1.3.6.1.4.1.2021.8.1.1.3 = INTEGER: 3
.1.3.6.1.4.1.2021.8.1.2.1 = STRING: Downloads
.1.3.6.1.4.1.2021.8.1.2.2 = STRING: Website
.1.3.6.1.4.1.2021.8.1.2.3 = STRING: Total
.1.3.6.1.4.1.2021.8.1.3.1 = STRING: /usr/local/sbin/getbytes 1:10
.1.3.6.1.4.1.2021.8.1.3.2 = STRING: /usr/local/sbin/getbytes 1:20
.1.3.6.1.4.1.2021.8.1.3.3 = STRING: /usr/local/sbin/getbytes 1:1
.1.3.6.1.4.1.2021.8.1.100.1 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.100.2 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.100.3 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.101.1 = STRING: 761781376699
.1.3.6.1.4.1.2021.8.1.101.2 = STRING: 933523212201
.1.3.6.1.4.1.2021.8.1.101.3 = STRING: 1695410939529
.1.3.6.1.4.1.2021.8.1.102.1 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.102.2 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.102.3 = INTEGER: 0
.1.3.6.1.4.1.2021.8.1.103.1 = STRING:
.1.3.6.1.4.1.2021.8.1.103.2 = STRING:
.1.3.6.1.4.1.2021.8.1.103.3 = STRING:
Attachments
net-snmp_command.xml
net_snmp-command.xml
(1.37 KiB) Downloaded 577 times
arnolde
Posts: 9
Joined: Fri Feb 17, 2012 4:42 am

Re: External command datasource (.xml) for Net-SNMP/UCD-SNMP

Post by arnolde »

I've just tried this, but I can't seem to get it working.
I have a custom script triggered via SNMPD which returns the output of my solar inverters from SolarMax.
(In case anybody else is interested, the short perl script is attached)

Output from SNMPWALK to OID .1.3.6.1.4.1.2021.8.1.101:

UCD-SNMP-MIB::extOutput.1 = STRING: 432
UCD-SNMP-MIB::extOutput.2 = STRING: 266

The host device is already configured in Cacti and succussfully graphs interface stats, hdd space, etc.

Can somebody please post step-by-step instructions on how to create a datasource/dataquery/graph/whatever I need to simply display these 2 values as graphs?
Ideally I'd like one graph with the output1 value as a taller background filled area, and the second value (which is always smaller) as a foreground filled area.
But I can play with the graph details later, right now I'm just hoping for some help on getting them graphed any way.

regards,
Ethan

Code: Select all

~# cat solarmax1.pl
#!/usr/bin/perl

use IO::Socket;

my $REMOTE = new IO::Socket::INET (
        PeerAddr => '192.168.0.195',
        PeerPort => '12345',
        Proto => 'tcp',
        Timeout => '1',
        Blocking => '0' );

die "can't connect - connection busy?" unless $REMOTE;
$REMOTE->autoflush(1);

$command="PAC;KDY;UDC;IDC;TKK;TK1;TK2";
  $dev=1;
  $query="FB;" . sprintf("%02x",$dev) . ";" .  sprintf("%02x",19+length($command)) . "|64:".$command."|";
  print $REMOTE "{".$query.sprintf("%04x", (unpack ("%16C*", $query)))."}\n";
  select(undef,undef,undef, .1); # sleep 100ms

while (sysread($REMOTE, $byte, 1) == 1) {
  $response=$response.$byte;
  if ($byte eq "}") {
    if ($response =~ /^.(.{2}).*\|64:PAC=(.+)\|.*/) {
      print hex($2)/2 . "\n";
    } else {
      print "-1\n";
    }
    $response="";
  }
}                                                                                                                                                                                                                                 close($REMOTE);
I have 2 files, solarmax1.pl and solarmax2.pl (which is identical but for the $dev=2) on my NAS (Buffalo Linkstation Quad) running Linux, which in turn queries the inverters (which unfortunately are not SNMP capable) and I want Cacti running on my public webserver to graph the power output. (Also I'm working on an embedded Linux SBC with many temperature sensors and later want to also graph things like boiler temp, outside temp, solar temp, etc.

EDIT: If I walk with OID .1.3.6.1.4.1.2021.8.1, I get:

UCD-SNMP-MIB::extIndex.1 = INTEGER: 1
UCD-SNMP-MIB::extIndex.2 = INTEGER: 2
UCD-SNMP-MIB::extNames.1 = STRING: SolarPAC1
UCD-SNMP-MIB::extNames.2 = STRING: SolarPAC2
UCD-SNMP-MIB::extCommand.1 = STRING: /root/solarmax1.pl
UCD-SNMP-MIB::extCommand.2 = STRING: /root/solarmax2.pl
UCD-SNMP-MIB::extResult.1 = INTEGER: 0
UCD-SNMP-MIB::extResult.2 = INTEGER: 0
UCD-SNMP-MIB::extOutput.1 = STRING: 520
UCD-SNMP-MIB::extOutput.2 = STRING: 315
UCD-SNMP-MIB::extErrFix.1 = INTEGER: noError(0)
UCD-SNMP-MIB::extErrFix.2 = INTEGER: noError(0)
UCD-SNMP-MIB::extErrFixCmd.1 = STRING:
UCD-SNMP-MIB::extErrFixCmd.2 = STRING:

The ExtOutput 1 and 2 are what I want.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests