SNMP Data Query with regex processing

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

Moderators: Moderators, Developers

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

SNMP Data Query with regex processing

#1 Post by RaduAlexandru » Mon Sep 30, 2019 7:19 pm

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

[email protected]:~$ 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.


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

Re: SNMP Data Query with regex processing

#3 Post by RaduAlexandru » Mon Oct 21, 2019 7:50 pm

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: 3080
Joined: Sun Aug 27, 2017 12:05 am

Re: SNMP Data Query with regex processing

#4 Post by netniV » Tue Oct 22, 2019 6:21 am

Can you export your template and XML file and upload them here. I have a QNAP here I can probably test this against.

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

Re: SNMP Data Query with regex processing

#5 Post by RaduAlexandru » Tue Oct 22, 2019 9:21 am

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 8 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

#6 Post by RaduAlexandru » Wed Oct 30, 2019 10:55 am

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 User
Posts: 361
Joined: Wed Dec 07, 2011 9:19 am

Re: SNMP Data Query with regex processing

#7 Post by Rno » 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
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.8
Spine 1.2.8
thold 1.0.6
monitor 2.3.5
syslog 2.4
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.7

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

Re: SNMP Data Query with regex processing

#8 Post by RaduAlexandru » Wed Oct 30, 2019 4:37 pm

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: 3080
Joined: Sun Aug 27, 2017 12:05 am

Re: SNMP Data Query with regex processing

#9 Post by netniV » Wed Oct 30, 2019 7:02 pm

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.

Post Reply