Cannot get SNMP query to work

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

Moderators: Developers, Moderators

Post Reply
User avatar
bleearg
Cacti User
Posts: 55
Joined: Wed Apr 27, 2005 9:37 am

Cannot get SNMP query to work

Post by bleearg »

I have had it, I've been trying to get this query working for two days now. I have tried dozens of permutations of the XML file and simply cannot figure this out. Please tell me what I am doing wrong. I have read the docs on SNMP data queries no less than 25 times, so clearly something is not sinking in. Forum searches result in people with a similar problem and the answer is simply "I fixed it" with no description whatsoever on what was done. Thanks a lot. This is just the latest iteration of my file:

Code: Select all

<interface>
        <name>Get OptiDriver port list for optical diagnostics</name>
        <oid_index>.1.3.6.1.4.1.629.200.8.1.1.1</oid_index>
        <oid_index_parse>OID/REGEXP:^.{29}(.*)</oid_index_parse>
        <index_order>nbsCmmcPortChassisIndex</oid_index_order>
        <index_order_type>numeric</index_order_type>

        <fields>
                <nbsCmmcPortChassisIndex>
                        <name>Index</name>
                        <method>walk</method>
                        <source>index</source>
                        <direction>input</direction>
                </nbsCmmcPortChassisIndex>
                <nbsCmmcPortName>
                        <name>Port Name</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.21</oid>
                </nbsCmmcPortName>
                <nbsCmmcPortTxPower>
                        <name>Transmit Power</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.31</oid>
                </nbsCmmcPortTxPower>
                <nbsCmmcPortRxPower>
                        <name>Receive Power</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.32</oid>
                </nbsCmmcPortRxPower>
        </fields>
</interface>
Since there is no index OID in this table, I need to grab the last several digits in the OID being walked. This is what an snmpwalk looks like and the numbers I need to grab are in bold:

.1.3.6.1.4.1.629.200.8.1.1.1.1.14.1 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.14.2 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.14.3 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.14.4 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.16.1 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.16.2 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.16.3 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.16.4 (integer) 1
.1.3.6.1.4.1.629.200.8.1.1.1.1.16.5 (integer) 1

This is what I get when I do a verbose query:

Code: Select all

Total: 0.000000, Delta: 0.000000, Running data query [27].
Total: 0.000000, Delta: 0.000000, Found type = '3' [SNMP Query].
Total: 0.010000, Delta: 0.000000, Found data query XML file at '/var/www/XXXXXXXX/htdocs/resource/snmp_queries/optidriver_ports3.xml'
Total: 0.010000, Delta: 0.000000, Error parsing XML file into an array.
Total: 0.010000, Delta: 0.000000, Found data query XML file at '/var/www/XXXXXXXX/htdocs/resource/snmp_queries/optidriver_ports3.xml'
Total: 0.010000, Delta: 0.000000, Found data query XML file at '/var/www/XXXXXXXX/htdocs/resource/snmp_queries/optidriver_ports3.xml'
Total: 0.010000, Delta: 0.000000, Update data query sort cache complete
Total: 0.010000, Delta: 0.000000, Updated data query index ordering
Total: 0.010000, Delta: 0.000000, Found data query XML file at '/var/www/XXXXXXXX/htdocs/resource/snmp_queries/optidriver_ports3.xml'
Total: 0.020000, Delta: 0.010000, Update re-index cache complete
Total: 0.020000, Delta: 0.000000, Update graph data query cache complete
Total: 0.020000, Delta: 0.000000, Update data source data query cache complete
Total: 0.020000, Delta: 0.000000, Update data query cache complete
Total: 0.020000, Delta: 0.000000, Update poller cache from query complete
Total: 0.020000, Delta: 0.000000, Automation execute data query complete
Total: 0.020000, Delta: 0.000000, Plugin hooks complete
I have other SNMP queries somewhat similar to this that I configured years ago and tried to follow their examples, but no matter what I do, I end up with no results but total and utter failure. I just want to get this done and move on, so someone please tell me what I am doing wrong here.

EDIT: I finally got it working. This is what I ended up with, after correcting a 'direction' mistake and modifying the regex.

Code: Select all

<interface>
        <name>Get OptiDriver port list for optical diagnostics</name>
        <oid_index>.1.3.6.1.4.1.629.200.8.1.1.3</oid_index>
        <oid_index_parse>OID/REGEXP:^.*([12]\.[0-9][0-9]{0,1}\.[0-9][0-9]{0,1})$</oid_index_parse>
        <index_order>nbsCmmcPortIndex</index_order>
        <index_order_type>alphabetic</index_order_type>

        <fields>
                <nbsCmmcPortIndex>
                        <name>nbsCmmcPortIndex</name>
                        <method>walk</method>
                        <source>OID/REGEXP:^.*([12]\.[0-9][0-9]{0,1}\.[0-9][0-9]{0,1})$</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.3</oid>
                </nbsCmmcPortIndex>
                <nbsCmmcPortName>
                        <name>Port Name</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.21</oid>
                </nbsCmmcPortName>
                <nbsCmmcPortTxPower>
                        <name>Transmit Power</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.31</oid>
                </nbsCmmcPortTxPower>
                <nbsCmmcPortRxPower>
                        <name>Receive Power</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.32</oid>
                </nbsCmmcPortRxPower>
        </fields>
</interface>
Last edited by bleearg on Fri Aug 31, 2018 8:06 am, edited 1 time in total.
User avatar
bleearg
Cacti User
Posts: 55
Joined: Wed Apr 27, 2005 9:37 am

Re: Cannot get SNMP query to work

Post by bleearg »

I've updated my query file to correct some possible errors I found, but still no luck:

Code: Select all

<interface>
        <name>Get OptiDriver port list for optical diagnostics</name>
        <oid_index>.1.3.6.1.4.1.629.200.8.1.1</oid_index>
        <oid_index_parse>OID/REGEXP:^.{29}(.*)</oid_index_parse>
        <index_order>nbsCmmcPortIndex</oid_index_order>
        <index_order_type>numeric</index_order_type>

        <fields>
                <nbsCmmcPortIndex>
                        <name>Index</name>
                        <method>walk</method>
                        <source>index</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.3</oid>
                </nbsCmmcPortIndex>
                <nbsCmmcPortName>
                        <name>Port Name</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.21</oid>
                </nbsCmmcPortName>
                <nbsCmmcPortTxPower>
                        <name>Transmit Power</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.31</oid>
                </nbsCmmcPortTxPower>
                <nbsCmmcPortRxPower>
                        <name>Receive Power</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.629.200.8.1.1.32</oid>
                </nbsCmmcPortRxPower>
        </fields>
</interface>
I've also tried this as the regex:

OID/REGEXP:^.{29}(\.[12]\.[0-9][0-9]{0,1}\.[0-9][0-9]{0,1})$

While the regex matches the OID string in a regex evaluator, I still get the same results - nothing in my query.
rasekm
Posts: 25
Joined: Thu Aug 23, 2018 7:28 am

Re: Cannot get SNMP query to work

Post by rasekm »

OID/REGEXP:\d*\.\d*\.\d*$

Try this regex
User avatar
bleearg
Cacti User
Posts: 55
Joined: Wed Apr 27, 2005 9:37 am

Re: Cannot get SNMP query to work

Post by bleearg »

Thanks for the suggestion. I edited the original post with what I found to work.

My issues with this were:

1. The documentation for 1.x is just...not good. There's actually better documentation for building a custom SNMP query file for the 0.8.7 release at https://docs.cacti.net/manual:087:3a_ad ... alkthrough.
2. The forum, while having good intentions, kind of sucks for searching. Doing a search often leads to a failure because the search terms "are too common words".
3. I misunderstood how the query works. I thought that it uses the index that is found via the regex in the oid_index_parse tag and then just appends that to the rest of the OIDs in the rest of the XML file. This isn't what it does. It uses that entire regex in every section, so if you have a regex that uses something like ^.*{29}, as I did in several of my iterations, it didn't work for my 'Port Name', 'Transmit Power' or 'Receive Power' OIDs because of the one extra digit in the OID definition.
User avatar
camerabob
Cacti User
Posts: 386
Joined: Fri Feb 10, 2017 2:45 pm
Location: Long Island, New York, USA
Contact:

Re: Cannot get SNMP query to work

Post by camerabob »

You could clean it up a bit...

^.{29}(\.[12]\.[0-9]{1,2}\.[0-9]{1,2})$
Prod: Cacti 1.2.15 @ CentOS Linux release 7.9.2009 (Core) & PHP 5.4.16-48.el7
Maint @ 1.2
Monitor @ 2.3.6
Thold @ 1.2.4

Temp: Cacti 1.2.3 @ CentOS Linux release 7.9.2009 (Core) & PHP 5.4.16-48.el7
Flowview @ 2.1
Mactrack @ 4.2
Maint @ 1.2
Monitor @ 2.3.6
Router Configs @ 1.3.4
Syslog Monitoring @ 2.1
Thold @ 1.2.4
User avatar
bleearg
Cacti User
Posts: 55
Joined: Wed Apr 27, 2005 9:37 am

Re: Cannot get SNMP query to work

Post by bleearg »

Cool, thanks for that suggestion. Implemented.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests