Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


<value_index_parse>and re-write of function query_snmp

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Tue Sep 11, 2007 1:06 pm    Post subject: <value_index_parse>and re-write of function query_snmp Reply with quote

Background
Having used Cricket (with contributed program genRtrConfig) for many years, I
am missing cli/add_graphs_for_intresting_interfaces.
This is where one doesn't graph a lot of unintresting interfaces.
cli/add_graphs can produce a lot of unintresting graphs if used on, say, a large ATM router.

I have chosen to concentrate on the xml file in detail as this would mean automization via cli/add_graphs.

Proof of concept by altering lib/data_query.php function query_snmp_host($host_id, $snmp_query_id)
- the original filter idea is also enhanced with the idea of coupling two mib areas under one index (http://forums.cacti.net/viewtopic.php?p=111049#111049)

Status: Works.

http://bugs.cacti.net/view.php?id=1009 - feature request for 0.8.8 (0.8.7 is feature frozen)
I'm reading thru forums to see if there are other syntax things I could use for the sake of completeness
- if I have overlooked one, please post
Coding for a complete solution starts after final release of 0.8.7 and will be checked on CentOS VM machine and Windows based on the 0.8.7 code.

Thanks to:
Feedback: shull

Forum links:
For:
- http://forums.cacti.net/viewtopic.php?t=14343
Quote:
I have seen several MIB's where an index is used to point to other locations in the mib with a little extension (of 2 numbers)

- http://forums.cacti.net/viewtopic.php?t=22586
The answer could be: http://forums.cacti.net/viewtopic.php?p=111049#111049

For:
- http://forums.cacti.net/viewtopic.php?t=13949
Quote:
I think that would be great if Cacti have some kind of "VALUE/REGEXP_REPLACE" option in the <source> field!
And it would be great too if using "VALUE/REGEXP" we have the possibility to match more than one value in the <source> field!

The answer could be <this post>

For:
- http://forums.cacti.net/viewtopic.php?p=79398
Quote:
I'm wondering if there is some way to have cacti "ignore" indexes with certain values...

The answer could be <this post>

For:
- http://forums.cacti.net/viewtopic.php?t=23298
Quote:
I'd like to work around this, so I can create a "master host template" which requires minimal input:
- description, hostname, interfaces to be graphed

Interpreting as cli/add-graphs (of intresest)

Bugs/changes found:
http://bugs.cacti.net/view.php?id=522

Introducing:
<value_index_parse>VALUE/REGEXP:<ereg>:REPLACE:<whatever>:TEST:<it></value_index_parse>
Let's take interfaces.xml and add <value_index_parse>
Code:

<interface>
        <name>Get intresting SNMP Interfaces</name>
        <description>Queries a host for a list of monitorable interfaces that are "intresting" after ifType for example</description>
        <oid_index>.1.3.6.1.2.1.2.2.1.3</oid_index>
        <oid_num_indexes>.1.3.6.1.2.1.2.2.1.3.0</oid_num_indexes>
        <value_index_parse>VALUE/REGEXP:<regexp>:REPLACE:<with>:TEST:<it></value_index_parse>
        <index_order>ifDescr:ifName:ifHwAddr:ifIndex</index_order>
        <index_order_type>numeric</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <ifIndex>
                        <name>Index</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.2.2.1.1</oid>
                </ifIndex>
                <ifAlias>
                        <name>Alias (IF-MIB)</name>
                        <method>walk</method>
                        <source>value</source>
                        <value_index_parse>VALUE/REGEXP:<regexp>:REPLACE:<with>:TEST:<it></value_index_parse>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.31.1.1.1.18</oid>
                </ifAlias>
                <ifType>
                        <name>Type</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.2.2.1.3</oid>
                        </ifType>


The index values are tested for a regexp replace for true -> index is intresting and only intresting index's are saved to host_snmp_cache which is used by the calling functions to present which graphs can be graphed.
The code used is altered lib/data_query.lib function query_snmp_host

Quote:
What do would you use it for

Show only interfaces with, say, ifAlias !=''.
Typically in cisco world where the only interfaces you want graphed have description on the interface.
When the cisco device has a lot of interfaces, the select all is easier than going through the interfaces one by one.
Also, cli/add_graphs would be better as in the present beta, it would add all interfaces should be graphed: a lotta graphs if one is to automaise all devices ...

Proof of Concept code / XML and Image
- in next post: http://forums.cacti.net/viewtopic.php?p=110598#110598

At your own risk:
Use svn version that data_qery.php is based on and replace with enclosed.
Replave interface.xml with enclose xml.

ToDo:
- collect from forums all examples of all requirements
- think
-- syntax thoughts http://forums.cacti.net/viewtopic.php?p=110632#110632
- code again for 0.8.7 final release

XML example
Couples cdp cache index and ifIndex
Filter just ethernet interface
Code:
<interface>
        <name>Get SNMP Interfaces</name>
        <description>Queries a host for a list of monitorable interfaces</description>
        <oid_index>.1.3.6.1.2.1.2.2.1.1</oid_index>
        <oid_num_indexes>.1.3.6.1.2.1.2.1.0</oid_num_indexes>
        <index_order>ifDescr:ifName:ifHwAddr:ifIndex</index_order>
        <index_order_type>numeric</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <ifIndex>
                        <name>Index</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.2.2.1.1</oid>
                </ifIndex>
                <ifOperStatus>
                        <name>Status</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.2.2.1.8</oid>
                </ifOperStatus>
                <ifDescr>
                        <name>Description</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.2.2.1.2</oid>
                </ifDescr>
                <ifName>
                        <name>Name (IF-MIB)</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.31.1.1.1.1</oid>
                </ifName>
                <ifAlias>
                        <name>Alias (IF-MIB)</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.31.1.1.1.18</oid>
                </ifAlias>
                <ifType>
                        <name>Type</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.2.2.1.3</oid>
                        <value_index_parse>VALUE/REGEXP:.*\(6\).*:REPLACE::TEST:</value_index_parse>
                </ifType>
                <ifIP>
                        <name>IP Address</name>
                        <method>walk</method>
                        <source>OID/REGEXP:.*\.([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.2.1.4.20.1.2</oid>
                </ifIP>
                <cdpCacheSysName>
                        <name>cdpCacheSysName</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.9.9.23.1.2.1.1.6</oid>
                        <oid_index_parse>OID/REGEXP:.*\.([0-9]*)\.[0-9]*$:REPLACE:\\1</oid_index_parse>
                </cdpCacheSysName>
        </fields>
</interface>


Last edited by oxo-oxo on Tue Sep 18, 2007 6:15 am; edited 57 times in total
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Tue Sep 11, 2007 5:45 pm    Post subject: Reply with quote

XML and code attached for index filtering but this is a historical attachment and new code will be produced after final 0.8.7 release


cacti.JPG
 Description:
 Filesize:  144.82 KB
 Viewed:  4628 Time(s)

cacti.JPG



data_query.php.txt
 Description:
Based on SVN revision 4151

Download
 Filename:  data_query.php.txt
 Filesize:  30.73 KB
 Downloaded:  235 Time(s)


int-oxo.xml
 Description:

Download
 Filename:  int-oxo.xml
 Filesize:  4.44 KB
 Downloaded:  258 Time(s)



Last edited by oxo-oxo on Tue Sep 18, 2007 12:32 am; edited 14 times in total
Back to top
rony
Developer/Forum Admin


Joined: 17 Nov 2003
Posts: 5469
Location: Wisconsin, USA

PostPosted: Tue Sep 11, 2007 7:10 pm    Post subject: Reply with quote

Search is your friend....

Whatever you are trying to do has already probably been done.
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Wed Sep 12, 2007 12:21 am    Post subject: Reply with quote

Syntax thoughts ...:

Quote:
<index_parse>VALUE/REGEXP:<regexp>:REPLACE:<with>:TEST:<it></index_parse>
<index_parse>OID/REGEXP:<regexp>:REPLACE:<with>:TEST:<it></index_parse>


instead of <value_index_parse> as it is quite possible that one may only be intrested in specific OIDS that contain values like ip address.

<index_parse_logic> " something "</index_parse_logic>

For example, interesting interface if ifAlias or cdpCacheSysName AND ifType could be:
Quote:
<index_parse_logic>(['ifAlias'] || ['ifDescr'])&&['ifType']</index_parse_logic>


Last edited by oxo-oxo on Tue Sep 18, 2007 11:11 am; edited 34 times in total
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Thu Sep 13, 2007 5:20 am    Post subject: Reply with quote

Removed to make post smaller (was historical document)

Last edited by oxo-oxo on Tue Sep 18, 2007 12:33 am; edited 1 time in total
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Sat Sep 15, 2007 10:23 am    Post subject: Reply with quote

Removed to make post smaller (was historical document)

Last edited by oxo-oxo on Tue Sep 18, 2007 12:31 am; edited 1 time in total
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Mon Sep 17, 2007 4:31 pm    Post subject: Reply with quote

Removed to make post smaller (was historical document)

Last edited by oxo-oxo on Tue Sep 18, 2007 12:38 am; edited 1 time in total
Back to top
shull
Cacti User


Joined: 24 Aug 2006
Posts: 54
Location: South Texas

PostPosted: Mon Sep 17, 2007 9:18 pm    Post subject: Reply with quote

This is excellent!!!

Great work on this. I took the time to run through all of the links and read the posts that you referenced. This is an excellent solution to several problems. I can see that by using this *new* XML field, it can open up some possibilities within Cacti that you couldn't do before. This is definitely something that can greatly enhance Cacti.

I am going to implement this extra field within the CactiXML tool that I will publish soon.

As a note to the developers, you should really consider this to the core app. The hard work has already been done. Also, this can be pretty easily tested.



-Stephen
Back to top
deu439356



Joined: 13 Aug 2008
Posts: 45

PostPosted: Wed Oct 29, 2008 4:33 pm    Post subject: Reply with quote

Does anyone know how to modify the ifindex? The OID below gets the ifIndex, but once the ifIndex is retrieved, I need to append a .1 to the of the ifIndex. So, if the below OID retrieves an ifIndex of 255, I need to change that to be 255.1

Code:
<interface>
        <name>Get  SNMP information</name>
        <description>Queries for data</description>
        <oid_index>.1.3.6.1.2.1.2.2.1.1</oid_index>
        <index_order_type>numeric</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>
<fields>
                <ifIndex>
                        <name>Index</name>
                        <source>index</source>
                        <method>walk</method>
                        <direction>input</direction>
                </ifIndex>



Any suggestions? Thanks!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group