SNMP Data Query with regex processing

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

Moderators: Developers, Moderators

Post Reply
User avatar
RaduAlexandru
Posts: 43
Joined: Mon Mar 28, 2005 5:06 pm
Location: Bucharest, Romania
Contact:

SNMP Data Query with regex processing

Post by RaduAlexandru »

Hello!
I was wondering if anyone could help me with a issue I have with a snmp data query.

I attempted to make my own graphs for a qnap device, using this (somewhat dated) tutorial: https://docs.cacti.net/manual:100:3a_ad ... alkthrough
I did manage to make another graph template for the fans, but for the hdd temps I kind of hit an wall... I get strange data back and I can't figure out why.

I pasted here snmptable output:

Code: Select all

user@host:~$ snmptable -m ALL -v2c -c public 10.1.0.10 .1.3.6.1.4.1.24681.1.2.11
Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU
SNMP table: NAS-MIB::systemHdTable

 hdIndex hdDescr hdTemperature hdStatus              hdModel hdCapacity hdSmartInfo
       1  "HDD1"   "-- C/-- F"   noDisk                 "--"       "--"        "--"
       2  "HDD2"   "-- C/-- F"   noDisk                 "--"       "--"        "--"
       3  "HDD3"   "-- C/-- F"   noDisk                 "--"       "--"        "--"
       4  "HDD4"   "-- C/-- F"   noDisk                 "--"       "--"        "--"
       5  "HDD5"   "29 C/84 F"    ready "WD2002FFSX-68PF8N0"  "1.82 TB"      "GOOD"
       6  "HDD6"   "29 C/84 F"    ready "WD2002FFSX-68PF8N0"  "1.82 TB"      "GOOD"
       7  "HDD7"   "29 C/84 F"    ready "WD2002FFSX-68PF8N0"  "1.82 TB"      "GOOD"
       8  "HDD8"   "28 C/82 F"    ready "WD2002FFSX-68PF8N0"  "1.82 TB"      "GOOD"
And yet my graphs show temperatures between 2.8k an 3.0k (yes, 3000 degrees Celsius). I can't figure out what I did wrong...
Image

This is my snmp data query xml

Code: Select all

<interface>
    <name>Get NAS-MIB::systemHdTable Information</name>
    <description>Get SNMP based Fan Information out of NAS-MIB::systemHdTable</description>
    <index_order>hdDescr:hdIndex</index_order>
    <index_order_type>numeric</index_order_type>
    <oid_index>.1.3.6.1.4.1.24681.1.2.11.1.1</oid_index>
    <oid_num_indexes>.1.3.6.1.4.1.24681.1.2.10.0</oid_num_indexes>

    <fields>
        <hdIndex>
            <name>Index</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.1</oid>
        </hdIndex>
        <hdDescr>
            <name>Description</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.2</oid>
        </hdDescr>
        <hdTemperature>
            <!-- Sample value: "27 C/80 F" -->
            <name>Temperature</name>
            <method>walk</method>
            <source>value</source>
            <direction>input-output</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.3</oid>
        </hdTemperature>
        <hdTemperatureC>
            <!-- Sample value: "27 C/80 F" -->
            <name>Temperature in Celsius</name>
            <method>walk</method>
            <source>VALUE/REGEX:((?:\+|-)?\s*\d+(?:\.\d+)?)\s*C\/(?:\+|-)?\s*(?:\+|-)?\s*\d+(?:\.\d+)?\s*F</source>
            <direction>input-output</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.3</oid>
        </hdTemperatureC>
        <hdTemperatureF>
            <!-- Sample value: "27 C/80 F" -->
            <name>Temperature in Fahrenheit</name>
            <method>walk</method>
            <source>VALUE/REGEX:(?:\+|-)?\s*\d+(?:\.\d+)?\s*C\/((?:\+|-)?\s*(?:\+|-)?\s*\d+(?:\.\d+)?)\s*F</source>
            <direction>input-output</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.3</oid>
        </hdTemperatureF>
        <hdStatus>
            <name>Status</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.4</oid>
        </hdStatus>
        <hdModel>
            <name>Model</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.5</oid>
        </hdModel>
        <hdCapacity>
            <name>Capacity</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.6</oid>
        </hdCapacity>
        <hdSmartInfo>
            <name>Smart Info</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.4.1.24681.1.2.11.1.7</oid>
        </hdSmartInfo>
    </fields>
</interface>

Any help or suggestions would be greatly appreciated.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: SNMP Data Query with regex processing

Post by netniV »

Did you make sure it was set to SNMP Indexed?
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
User avatar
RaduAlexandru
Posts: 43
Joined: Mon Mar 28, 2005 5:06 pm
Location: Bucharest, Romania
Contact:

Re: SNMP Data Query with regex processing

Post by RaduAlexandru »

Unfortunately yes...
Image

The odd part is I don't think cmd.php cares about the REGEXP at all.
Image
As you can see above, the regex is working, but cmd.php never seems to call the functions that deal with REXGEXP parsing.
As far as I can tell, the function that does the REGEXP parsing is query_snmp_host from <cacti_root>/lib/data_query.php, but cmd.php never includes that.
Also, tracing execution of cmd.php, seems that all it does is call cacti_snmp_session_get from <cacti_root>/lib/snmp.php, which in turn calls format_snmp_string, and that is where a number is expected as a result, thus all non digit characters are just stripped.

For now I'm using a hack, a CDEF function

Code: Select all

CURRENT_DATA_SOURCE,10000,LT,CURRENT_DATA_SOURCE,100,/,FLOOR,CURRENT_DATA_SOURCE,1000,/,FLOOR,IF
But I find this to be a little tacky.


Thank you in advance for any further assistance.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: SNMP Data Query with regex processing

Post by netniV »

Can you export your template and XML file and upload them here. I have a QNAP here I can probably test this against.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
User avatar
RaduAlexandru
Posts: 43
Joined: Mon Mar 28, 2005 5:06 pm
Location: Bucharest, Romania
Contact:

Re: SNMP Data Query with regex processing

Post by RaduAlexandru »

I attached the zip
Attachments
NAS-MIB.systemHdTable.zip
ZIP containing the templates, snmp_query xml file and the MIB I used to create them
(16.5 KiB) Downloaded 140 times
User avatar
RaduAlexandru
Posts: 43
Joined: Mon Mar 28, 2005 5:06 pm
Location: Bucharest, Romania
Contact:

Re: SNMP Data Query with regex processing

Post by RaduAlexandru »

I apologize for being impatient and a nag (and for double posting), but have you had time to take a look at it?
Rno
Cacti Pro User
Posts: 709
Joined: Wed Dec 07, 2011 9:19 am

Re: SNMP Data Query with regex processing

Post by Rno »

I'm not sure you can do that:
<direction>input-output</direction>

it's either an output or a input, not both

Usually index use input, data use output
Test
Almalinux
php 8.2.14
mariadb 10.6.16
Cacti 1.2.27
Spine 1.2.27
RRD 1.7.2
thold 1.8
monitor 2.5
syslog 3.2
flowview: 3.3
weathermap 1.0 Beta
User avatar
RaduAlexandru
Posts: 43
Joined: Mon Mar 28, 2005 5:06 pm
Location: Bucharest, Romania
Contact:

Re: SNMP Data Query with regex processing

Post by RaduAlexandru »

Rno wrote: Wed Oct 30, 2019 11:13 am I'm not sure you can do that:
<direction>input-output</direction>

it's either an output or a input, not both

Usually index use input, data use output
That's used in <cacti_root>/resource/snmp_queries/interface.xml for ifOperStatus and ifAdminStatus. As far as I recall I took that from the docs, but I can't seem to find the page where I saw it.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: SNMP Data Query with regex processing

Post by netniV »

input-output is a valid field type, but it's not really well documented at the moment. Unfortunately, due to other circumstances, I haven't had a chance to test this at the office. Too many things occurring that have taken priority.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest