New script for gathering info on snmp server external script

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

Moderators: Developers, Moderators

Post Reply
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

New script for gathering info on snmp server external script

Post by jofficer »

I'm writing a script that will pull certain information about running processes.

I've got the script written, but I'm not certain I'm returning results like would be needed for a data template.

Right now, it's setup like this:

Code: Select all

./cmd-snmp.bash bash
app:bash pid: 818 cpu: 0.0 mem: totalmem: 2075708
app:bash pid: 1213 cpu: 0.0 mem: totalmem: 2075708
basically it gives you some basic stats for each argument passed to the script.

I'm sure I could add an index (appX) but I'm not certain how I'd pass this to a graph.
Last edited by jofficer on Mon Feb 18, 2008 6:42 pm, edited 1 time in total.
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

Have you read in the documentation site on how to create scripts/templates for cacti?
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

Post by jofficer »

I read this:

http://docs.cacti.net/node/224

But that by-itself wasn't overly helpful, although helpful in other regards. Does anyone have any specific examples of a script outputting multi-line data and graphing it?
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

Post by jofficer »

OK, I've change it up a little and am looking for some feedback. Here is what I've gotten from snmp host:

I've added the following to my host:

Code: Select all

extend showstat /bin/sh /tmp/var-cmd.sh agetty
On my Cacti box, I run this:

Code: Select all

snmpwalk -c public -v 1 vm3 NET-SNMP-EXTEND-MIB::nsExtendObjects
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".1 = STRING: agetty
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".2 = STRING: 7182
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".3 = STRING: 0.0
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".4 = STRING: 0.0
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".5 = STRING: 16314328
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".6 = STRING: agetty
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".7 = STRING: 7184
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".8 = STRING: 0.0
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".9 = STRING: 0.0
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".10 = STRING: 16314328
I can get the OIDs, I just posted common name for cleanliness. I can create the data sources, but I have a couple of questions.

1. NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".1 = STRING: agetty will actually return tty1 when I finish my script and NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat".6 will return tty2. what is the best way to tell cacti that a value being returned is the name of the following data instead of data itself?

I'm not sure if I'm saying this correctly. It's like when you run a query, you can see that a givein interface NAME is eth0 (or vlan5 or whatever) and thats the values of x.1 and x.2 are relevant to eth0. How can I do this in Cacti?
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

jofficer wrote:I'm not sure if I'm saying this correctly. It's like when you run a query, you can see that a givein interface NAME is eth0 (or vlan5 or whatever) and thats the values of x.1 and x.2 are relevant to eth0. How can I do this in Cacti?
Only if you create a data query script, then cacti will cache the names it collected. Then you can use them in graphs by adding |query_yourname|. Look at how the snmp interface data query and scripts are laid out.
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

Post by jofficer »

It's funny actually. I was doing exactly that when I received the notice of a new reply to this thread.

I still seem to be a bit stuck on a couple of items, and it's quite possible I'm just not doing this correctly. I've read through the linked references, and through the tutorial (for creating OID targets) but they really aren't that helpful. Decent for a general reference, but nothing specific.

On one of my hosts, I have the following added to snmpd.conf:

Code: Select all

extend .1.3.6.1.4.1.2021.51 showname /bin/sh /tmp/var-cmd.sh name
extend .1.3.6.1.4.1.2021.52 showcpu /bin/sh /tmp/var-cmd.sh cpu
extend .1.3.6.1.4.1.2021.53 showmem /bin/sh /tmp/var-cmd.sh mem
extend .1.3.6.1.4.1.2021.54 showtmem /bin/sh /tmp/var-cmd.sh tmem
from my cacti box, I can run the following:

Code: Select all

cacti snmp_queries # snmpwalk -c public -v1 vm3 .1.3.6.1.4.1.2021.51
UCD-SNMP-MIB::ucdavis.51.1.0 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.51.2.1.2.8.115.104.111.119.110.97.109.101 = STRING: "/bin/sh"
UCD-SNMP-MIB::ucdavis.51.2.1.3.8.115.104.111.119.110.97.109.101 = STRING: "/tmp/var-cmd.sh name"
UCD-SNMP-MIB::ucdavis.51.2.1.4.8.115.104.111.119.110.97.109.101 = ""
UCD-SNMP-MIB::ucdavis.51.2.1.5.8.115.104.111.119.110.97.109.101 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.51.2.1.6.8.115.104.111.119.110.97.109.101 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.51.2.1.7.8.115.104.111.119.110.97.109.101 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.51.2.1.20.8.115.104.111.119.110.97.109.101 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.51.2.1.21.8.115.104.111.119.110.97.109.101 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.51.3.1.1.8.115.104.111.119.110.97.109.101 = STRING: "squid-brk"
UCD-SNMP-MIB::ucdavis.51.3.1.2.8.115.104.111.119.110.97.109.101 = STRING: "squid-brk
watchtower4
kbtcsibkup1
gentoo_cacti"
UCD-SNMP-MIB::ucdavis.51.3.1.3.8.115.104.111.119.110.97.109.101 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.51.3.1.4.8.115.104.111.119.110.97.109.101 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.51.4.1.2.8.115.104.111.119.110.97.109.101.1 = STRING: "squid-brk"
UCD-SNMP-MIB::ucdavis.51.4.1.2.8.115.104.111.119.110.97.109.101.2 = STRING: "watchtower4"
UCD-SNMP-MIB::ucdavis.51.4.1.2.8.115.104.111.119.110.97.109.101.3 = STRING: "kbtcsibkup1"
UCD-SNMP-MIB::ucdavis.51.4.1.2.8.115.104.111.119.110.97.109.101.4 = STRING: "gentoo_cacti"
I've modified the interfaces.xml file heavily, and used the OID specific to the group of data I'm looking for:

Code: Select all

snmpwalk -On -c public -v1 vm3 .1.3.6.1.4.1.2021.51.4.1.2.8.115.104.111.119.110.97.109.101
.1.3.6.1.4.1.2021.51.4.1.2.8.115.104.111.119.110.97.109.101.1 = STRING: "squid-brk"
.1.3.6.1.4.1.2021.51.4.1.2.8.115.104.111.119.110.97.109.101.2 = STRING: "watchtower4"
.1.3.6.1.4.1.2021.51.4.1.2.8.115.104.111.119.110.97.109.101.3 = STRING: "kbtcsibkup1"
.1.3.6.1.4.1.2021.51.4.1.2.8.115.104.111.119.110.97.109.101.4 = STRING: "gentoo_cacti"
XML file:

Code: Select all

<interface>
        <name>Get VMWare Guest Stats</name>
        <description>Queries a host for a list of monitorable guest VMs</description>
        <index_order>vmDescr:vmCPU:vmMem:vmTMem</index_order>
        <index_order_type>numeric</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <vmDescr>
                        <name>Guest Name</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.51.4.1.2.8.115.104.111.119.110.97.109.101</oid>
                </vmDescr>
                <vmCPU>
                        <name>CPU Load</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.52.4.1.2.7.115.104.111.119.99.112.117</oid>
                </vmCPU>
                <vmMem>
                        <name>% MemoryType</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.53.4.1.2.7.115.104.111.119.109.101.109</oid>
                </vmMem>
                <vmTMem>
                        <name>Total Memory</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.54.4.1.2.8.115.104.111.119.116.109.101.109</oid>
                </vmTMem>
        </fields>
</interface>
Now, when I add the XML in Cacti, and add the data query to a host, I get the following error:

Code: Select all

Notice: Undefined index: oid_index in /usr/share/webapps/cacti/0.8.7a/htdocs/lib/data_query.php on line 167

Notice: Undefined index: oid_index in /usr/share/webapps/cacti/0.8.7a/htdocs/lib/data_query.php on line 172

Warning: Cannot modify header information - headers already sent by (output started at /usr/share/webapps/cacti/0.8.7a/htdocs/lib/data_query.php:167) in /usr/share/webapps/cacti/0.8.7a/htdocs/host.php on line 129
I'm sure this is probably due to a malformed XML file.

So thats where I'm at. Looking for feed back, happy to share once I'm finished.

For those interested, this is the start of a VMWare server guest monitoring template.

Cheers,
joey
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

1) Looks like you omitted the <oid_index> field from your new xml template. Does that MIB provide an index?

If not, then you'll have to do something like the following to try and pry out a index number:

Code: Select all

 <oid_index>NET-SNMP-EXTEND-MIB::nsExtendOutLine."showstat"</oid_index>
<oid_index_parse>OID/REGEXP:.*\.([0-9]{1,3})</oid_index_parse> 
I suggest you only use OIDs instead of their textual names in your templates too (I'm lazy to look up the OID of what I pasted).

2) A simple way to check if the XML is correctly formed, is opening it in your browser (IE is more picky than FF).
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

Post by jofficer »

What kind of output/data am I looking for the index values. I noticed in the interfaces one, it lists out .1 .2 .3 (etc...) through the total number of interfaces defined on the box. Is that what I'm looking for?
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

Yes. An index needs to be a unique value.
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

Post by jofficer »

I've modified my host to provide an index string, and I've added that to my .xml file in resources/snmp_queries. The sample output is as follows:

Code: Select all

snmpwalk -c public -v 1 vm3 .1.3.6.1.4.1.8072.1.3.2.4.1.2.9.115.104.111.119.105.110.100.101.120
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showindex".1 = STRING: 1
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showindex".2 = STRING: 2
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showindex".3 = STRING: 3
NET-SNMP-EXTEND-MIB::nsExtendOutLine."showindex".4 = STRING: 4
I tried a few more things, but am still unable to get this completed.

I believe there are two problems. The first (and possibly the only?) problem is that the RRD files are not being created.

I'd like to get this wrapped up, as I've spent a couple of days on this already. Short of creating duplicates of the generic SNMP templates (And polling each OID uniquely) can you offer some advice in how to set this correctly?

I'm happy to share screenshots of what I have thus far, if it would help?
jofficer
Posts: 35
Joined: Mon Feb 04, 2008 9:16 am

Post by jofficer »

I've gotten something like what I'm looking for, but I accomplished by entering the unique OIDs for the values I'm looking for.

What I'd like to do is plot each VM down the list, regardless of number of VMs. Essentially so I don't have to enter it each time.
Attachments
vmware_guest_load.png
vmware_guest_load.png (24.84 KiB) Viewed 3616 times
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests