Creating Data Source to store text values

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
n1els
Posts: 2
Joined: Sun Oct 25, 2015 7:33 am

Creating Data Source to store text values

Post by n1els »

Using cacti 0.88f.

In our environment we manage a bunch of end clients, who are mostly using Mikrotik routers. One of the challenges we have is version management. To keep this more manageable I want to collect some properties like sysName, sysDescr, sysLocation and .1.3.6.1.4.1.14988.1.1.4.4.0 (Mikrotik RouterOS version).

The first three are automatically visible in cacti when the device is added, but since I'd like to be able to pass this information on to another system I think that I might have to manually add them again in order to have this in a separate .rrd file. (for example to use in a Grafana dashboard)

To do this (and I could be completely on the wrong track here) I edited a perl script I found online and made this

Code: Select all

#!/usr/bin/perl
use warnings;
use strict;
use SNMP;
use Socket;

# VARIABLES YOU SHOULD EDIT.
my $comm = $ARGV[1];
my $dest = $ARGV[0];
my $mib  = $ARGV[3]; 
my $sver = $ARGV[2];

# VARIABLES YOU SHOULD LEAVE ALONE.
my $sess; # The SNMP::Session object that does the work.
my $var;  # Used to hold the individual responses.
my $vb;   # The Varbind object used for the 'real' query.

# Initialize the MIB (else you can't do queries).
&SNMP::initMib();

my %snmpparms;
$snmpparms{Community} = $comm;
$snmpparms{DestHost} = inet_ntoa(inet_aton($dest));
$snmpparms{Version} = $sver;
$snmpparms{UseSprintValue} = '1';
$sess = new SNMP::Session(%snmpparms);

# Turn the MIB object into something we can actually use.
$vb = new SNMP::Varbind([$mib,'0']); # '0' is the instance.

$var = $sess->get($vb); # Get exactly what we asked for.
if ($sess->{ErrorNum}) {
  die "Got $sess->{ErrorStr} querying $dest for $mib.\n";
  # Done as a block since you may not always want to die
  # in here.  You could set up another query, just go on,
  # or whatever...
}
#print $vb->tag, ".", $vb->iid, " : $var\n";
print "$var"
This then allows me to run the script from the command line:

Code: Select all

 perl snmp.pl 192.168.1.54 community 2c sysDescr
and get the output:

Code: Select all

RouterOS RB750
So when you have a few hundred clients, this is really helpful to remind you what kind of device you deployed there and so on. Of course a graph of this would be nonsense but it would be nice to have the data logged and accessible.

Now what I would like to do is to have cacti run this for me for every host, so (I think) I have to create a Data Source for this. So I have created this using http://www.cacti.net/downloads/docs/html/templates.html and other sources.

after this I am stuck and have no idea how to continue. My google-fu is also giving up, so I'm starting to wonder if this is even possible (because of the all-text values that you might get).

The ultimate goal would be to end up with a few .rrd files, collected by cacti, which I can then use elsewhere by just displaying the last value.
silvertip257
Posts: 33
Joined: Sun Mar 25, 2012 12:22 pm

Re: Creating Data Source to store text values

Post by silvertip257 »

Data Sources contain numeric values that go in a RRA (rrd file).
You can set up SNMP queries (XML file) to pull various values, which then will be placed in the SNMP Cache.
Once the value you want is in the SNMP Cache, reference it using |query| variables [0] in the Text Format field of a COMMENT graph item.

Utilities > System Utilities > View SNMP Cache

[0] http://www.cacti.net/downloads/docs/html/variables.html
Attachments
signal.png
signal.png (9.66 KiB) Viewed 763 times
silvertip257
n1els
Posts: 2
Joined: Sun Oct 25, 2015 7:33 am

Re: Creating Data Source to store text values

Post by n1els »

Hi silvertip257,

Thanks for pointing me in this direction.. I'll need to read into it before I can get started on it, but the concept as you explain it makes sense.

I'll update when I've made some progress.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests