Indexed SNMP Query for range of oids that have no index

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

Moderators: Developers, Moderators

Post Reply
Thrasher

Indexed SNMP Query for range of oids that have no index

Post by Thrasher »

I altered the code a bit to accomodate a phenomenon i found when looking to graph Windows 2000 CPU entries via SNMP.

The hrProcessorLoad oid at .1.3.6.1.2.1.25.3.3.1.2 has no index, yet you can walk this oid and get the load values of processors installed in a host. Without an index how could I get the appropriate oid for machines with more than one, two cpus etc?

The solution was to walk the oid itself and REGEXP the OID taking the last number and using that number as the snmp_index when inserting into the host_snmp_cache table.

for example the xml file portion for windows cpu:

Code: Select all

<index>
        <name>Index</name>
        <method>walk</method>
        <source>VALREP/REGEXP:.*\.([0-9]+)$</source>
        <direction>input</direction>
        <oid>.1.3.6.1.2.1.25.3.3.1.2</oid>
</index>
and the extra elseif in the snmp_functions.php file:

Code: Select all

}elseif (ereg("^VALREP/REGEXP:", $field_array["source"])) {
        for ($i=0;($i<sizeof($snmp_data));$i++) {
                $value = ereg_replace(ereg_replace("^VALREP/REGEXP:", "", $field_array["source"]), "\\1", $$
                $snmp_index = $value;
                $oid = $field_array["oid"] .  "." . $value;
         
                db_execute("replace into host_snmp_cache
                        (host_id,snmp_query_id,field_name,field_value,snmp_index,oid)
                        values ($host_id,$snmp_query_id,'$field_name','$value',$snmp_index,'$oid')");
        }
Perhaps this could be an enhancement to the program? unless there was another way i could have done this.

-Jeff
Thrasher

Post by Thrasher »

Ive changed my code to be a bit cleaner. My snmp_fuctions.php file at line 145 looks like so:

Code: Select all

}elseif (ereg("^OID/REGEXP:", $field_array["source"])) {
        for ($i=0;($i<sizeof($snmp_data));$i++) {
                $value = ereg_replace(ereg_replace("^OID/REGEXP:", "", $field_array["source"]), "\\1", $snmp_data[$i]["value"]);
                $snmp_index = $snmp_data[$i]["value"];
                $oid = $field_array["oid"] .  "." . $value;
                
                if (isset($field_array["replacesnmpindex"])) {
                        if ($field_array["replacesnmpindex"] == "true") {
                                $snmp_index = $value;
                        }
                }
                if (isset($field_array["hexdecode"])) {
                        if ($field_array["hexdecode"] == "true") {
                                $snmp_data[$i]["value"] = hex2bin(ereg_replace("[^A-Fa-f0-9]", "", $snmp_data[$i]["value"]));
                        }
                }
                 
                db_execute("replace into host_snmp_cache
                        (host_id,snmp_query_id,field_name,field_value,snmp_index,oid)
                        values ($host_id,$snmp_query_id,'$field_name','$value',$snmp_index,'$oid')");
        }
}
And now all i have to do is put a <replacesnmpindex>true</replacesnmpindex> in my xml file.

Also ive added a <hexdecode>true</hexdecode> option for when you want to decode hex strings into ASCII.

-Jeff
howard
Posts: 2
Joined: Wed Apr 30, 2003 1:58 am
Location: London
Contact:

Cannot quite see where this goes

Post by howard »

Jeff,

I have looked at snmp_functions.php (in the include directory?) and cannot see where your code would go. Some context woudl help!

Howard.
raX
Lead Developer
Posts: 2243
Joined: Sat Oct 13, 2001 7:00 pm
Location: Carlisle, PA
Contact:

Post by raX »

Do you know if these "index numbers" obtained from the last octect in the OID are apt to change often? One of my reasons for creating a script query to encapsulate this is I can enure the indexes are always sequential. Of course any script query that wraps a bunch of SNMP calls is not optimal.

I really like your idea here, but I would like to see it go further. I have run into a lot of MIBs that do not have indexes like you noticed here (Q-BRIDGE MIB comes to mind). However many times you cannot identify a value by simply looking at one octet, but many times a composite of two or more octects. It would be really cool to see Cacti parse the enough out of the OID to make each value unique and use that as the index. I think your code is on the right track and would need minimal modification to get there.

Also, could you provide a patch against version 0.8.5?

-Ian
mondaka
Posts: 18
Joined: Wed Mar 03, 2004 7:47 pm

Post by mondaka »

I tried to use the change proposed by Thrasher but it partially works with modifications, because i could extract the index in the first snmpwalk but in the next snmpwalk the index was lost.

I think that is because in the other source values, i mean: VALUE and VALUE/REGEXP there are no filter to extract or still using the same index extracted in the OID/REGEXP statement...

In the other hand i never find the snmp_functions.php file but i am working with cacti/lib/data_query.php in linux version, i supossed that's fine...

any comments are welcome.
mondaka
Posts: 18
Joined: Wed Mar 03, 2004 7:47 pm

Post by mondaka »

This is the Data Query Debug Output:

+ Running data query [13].
+ Found type = '3' [snmp query].
+ Found data query XML file at '/var/www/html/cacti/resource/snmp_queries/psax-bridge2atm'
+ XML file parsed ok.
+ Executing SNMP walk for list of indexes @ '.1.3.6.1.4.1.1751.2.18.12.13.1.9'
+ Located input field 'bridgeAtmPvcVccStatsInCellCountHiB' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.4.1.1751.2.18.12.13.1.9'
+ Found item [bridgeAtmPvcVccStatsInCellCountHiB='1506001.101001.2.214'] index: 1506001.101001.2.214 [from regexp oid parse]
+ Found item [bridgeAtmPvcVccStatsInCellCountHiB='1506002.101001.10.170'] index: 1506002.101001.10.170 [from regexp oid parse]
+ Found item [bridgeAtmPvcVccStatsInCellCountHiB='1506003.101001.10.973'] index: 1506003.101001.10.973 [from regexp oid parse]
+ Found item [bridgeAtmPvcVccStatsInCellCountHiB='1506004.101001.10.231'] index: 1506004.101001.10.231 [from regexp oid parse]
+ Located input field 'bridgeAtmPvcVccStatsOutCellCountHiB' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.4.1.1751.2.18.12.13.1.11'
+ Found item [bridgeAtmPvcVccStatsOutCellCountHiB='2.214'] index: 0 [from regexp oid parse]
+ Found item [bridgeAtmPvcVccStatsOutCellCountHiB='10.170'] index: 0 [from regexp oid parse]
+ Found item [bridgeAtmPvcVccStatsOutCellCountHiB='10.973'] index: 0 [from regexp oid parse]
+ Found item [bridgeAtmPvcVccStatsOutCellCountHiB='10.231'] index: 0 [from regexp oid parse]
mondaka
Posts: 18
Joined: Wed Mar 03, 2004 7:47 pm

Post by mondaka »

I had to modify the code proposed by Thrasher in order to extract the index correctly, really it wasn't too much.

}elseif (ereg("^OID/REGEXP:", $field_array["source"])) {
for ($i=0;($i<sizeof($snmp_data));$i++) {
$value = ereg_replace(ereg_replace("^OID/REGEXP:", "", $field_array["source"]), "\\1", $snmp_data[$i]["oid"]);
$snmp_index = $snmp_data[$i]["value"];
$oid = $field_array["oid"] . "." . $value;
if (isset($field_array["replacesnmpindex"])) {
if ($field_array["replacesnmpindex"] == "true") {
$snmp_index = $value;
}
}
debug_log_insert("data_query", "Found item [$field_name='$value'] index: $snmp_index [from regexp oid parse]");

if (isset($field_array["replacesnmpindex"])) {
if ($field_array["replacesnmpindex"] == "true") {
db_execute("replace into host_snmp_cache
(host_id,snmp_query_id,field_name,field_value,snmp_index,oid)
values ($host_id,$snmp_query_id,'$field_name','$value','$value','$oid')");
}
}elseif (isset($field_array["replacesnmpindex"])){
db_execute("replace into host_snmp_cache
(host_id,snmp_query_id,field_name,field_value,snmp_index,oid)
values ($host_id,$snmp_query_id,'$field_name','$value',$snmp_index,'$oid')");
}
}
jeffsan
Posts: 8
Joined: Fri Mar 05, 2004 12:49 pm

Post by jeffsan »

I can't seem to find this snmp_functions.php file (running ver 0.8.5) that you speak off. Is it possible to present the complete solution (ie the XML file, and the SNMP_Functions.PHP file) so I can integrate this into a data query? Your help is much appreciated.
PhilG
Posts: 7
Joined: Fri Feb 27, 2004 6:14 pm

VALUE/REGEXP syntax

Post by PhilG »

Hey folks!
I am trying to replace a string in some SNMP data that seems to causing problems with the GUI. I am querying a PIX firewall for the Interface descriptions and am receiving a response that looks like this:

Found item [ifDescr='PIX Firewall 'outside' interface'] index: 1 [from regexp value parse]

The additional ' characters surrounding the word outside seem to be preventing the GUI from using the ifDescr field in the tables and as a variable for naming the data sources and graphs. I have been able to change the VALUE/REGEXP: in my query xml file such that the ' is replaced with 1. When my query xml file looks like this:
<source>VALUE/REGEXP:'</source>
I get the following in the debug:
Found item [ifDescr='PIX Firewall \1outside\1 interface'] index: 1 [from regexp value parse]

This result allows the ifDescr to show up in the result tables and then I can use that field as a variable, but all of my names have a 1 substituted in such as:
PIX Firewall 1outside1 interface

Perhaps I just need some help with the replace syntax following VALUE/REGEXP:?

I can foresee that other SNMP data may need to have characters replaced as well so if this is not currently possible, perhaps it could be included in future releases?

I see where the 1 is coming from in the following code from data_query.xml:

$value = ereg_replace(ereg_replace("^VALUE/REGEXP:", "", $field_array["source"]), "\\1", $snmp_data[$i
]["value"]);

Thanks in advance for any thoughts and suggestions.
Philip Greenberg
rpingar

Post by rpingar »

I have a problem I think similar.

I have to graph the strengt of a wireless client's signal from my AP.

I know the OID to poll but it changes when a new client is associating to the ap because it is in a tab.

Do you have any idea on how to work around the OID dependancy from the clients associated?

thanks
PhiG

Wireless AP

Post by PhiG »

One thought is to identify something that does not change. For example, the client's MAC address and look through your vendor's MIBs to see if the MAC address is located somewhere and correlates to other MIB entries for the indexing purpose. I have not looked through any wireless MIBs recently so I cannot point you any further off-the-cuff. I'm still waiting to hear from someone working on development regarding my previous post.

Philip Greenberg
rpingar

Post by rpingar »

For exemple I know that the client I like to monitor is the last of the clients' tab. I know the "not changeble" OID about the number of clients associated. Giving the fact that I don't know the xml.......may you help me please?

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests