4

We know that Cacti uses SNMP to query and collect data. As far as i know SNMP manager uses Object ID (OID) to query about a certain object and get the response from an SNMP agent regarding that OID.

What confuses me is that how Cacti uses e.g. perl or python script to collect data? Does it use SNMP then? If so how the protocol works then?

1
  • @krisFR if the language is handling SNMP directly in a script, then they should load the relevant SNMP module first. right? but i am just seeing a plain generic perl script to query for memory usage...i think what you probably meant is that the script is first converted into a query, then SNMP using that query..please do correct me..
    – utlamn
    May 15, 2015 at 21:07

1 Answer 1

5

With Cacti you are not limited only to SNMP queries.

You can choose to run any script of your own as a Data Input Method. It could be Perl, PHP, Python, Bash or whatever. Just choose the Script/Command input type :

enter image description here

Your script has to output at least one value. This value will be attached to an output field within Cacti and used later to create the final graph.

If you only need one output field, just print the value as it is (eg 12) without anything else (eg ms, %) :

#!/bin/sh
ping -c1 host | grep rtt | cut -d"=" -f2 | cut -d"/" -f2

In case you have to retrieve multiple values, the output format has to be :

field1:value1 field2:value2 field3:value3

Then each field will be attached to an ouput field.

#!/bin/sh
result=$(ping -c1 host | grep rtt | cut -d"=" -f2)
min=$(echo $result | cut -d"/" -f1)
avg=$(echo $result | cut -d"/" -f2)
max=$(echo $result | cut -d"/" -f3)
echo "min:$min avg:$avg max:$max"

You can find further explanation and examples here :

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .