add_graphs.php with multiples --snmp-field and --snmp-value

Anything that you think should be in Cacti.

Moderators: Moderators, Developers

Post Reply
Author
Message
tsalle
Posts: 7
Joined: Thu Apr 28, 2011 3:37 am

add_graphs.php with multiples --snmp-field and --snmp-value

#1 Post by tsalle » Mon May 02, 2011 7:46 am

To automate cacti host and graphs creation, I've written a patch for the cli/add_graphs.php script.

With this patch you can now use the --snmp-field and --snmp-value multiple times for ds graphs creation.
For example, you can create graphs for a host with only interfaces with ifType=ethernetCsmacd and ifOperStatus=Up.

Example :

Code: Select all

php add_graphs.php --graph-type=ds --graph-template-id='22' --host-id=414 --snmp-query-id=1 --snmp-query-type-id='2' --snmp-field=ifType --snmp-value=ethernetCsmacd --snmp-field=ifOperStatus --snmp-value=Up
You can also uise the --snmp-value-regex instead of the --snmp-value option.
This is usefull if you want to create all interfaces like 'Port-channel'
Example :

Code: Select all

php add_graphs.php --graph-type=ds --graph-template-id='22' --host-id=414 --snmp-query-id=1 --snmp-query-type-id='2' --snmp-field=ifDescr --snmp-value-regex='Port-channel\d+'
Hope this will help..

NB. I posted a feature request on the mantis bug tracker : http://bugs.cacti.net/view.php?id=1986

Thierry.
Attachments
add_graphs.php.patch
cacti cli add_graphs.php patch to allow multiples --snmp-field and --snmp-value options.
(9 KiB) Downloaded 337 times

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: add_graphs.php with multiples --snmp-field and --snmp-va

#2 Post by gandalf » Sat May 14, 2011 3:20 pm

Thanks for issueing the mantis feature.
Personally, I'd like to advertise the AUTOM8 plugin which already supports such a feature
R.

X-dark
Cacti User
Posts: 111
Joined: Wed Jun 18, 2008 10:21 am
Location: France

Re: add_graphs.php with multiples --snmp-field and --snmp-va

#3 Post by X-dark » Wed Jun 08, 2011 8:04 am

gandalf wrote:Personally, I'd like to advertise the AUTOM8 plugin which already supports such a feature
Yes similar feature can be achieved with autom8 but sometimes it is more appropriate to use the cli scripts to perform some tasks. Such enhancement could then be useful anyway.
Cedric Girard

mstbone67a
Posts: 24
Joined: Mon Sep 21, 2009 9:31 am

Re: add_graphs.php with multiples --snmp-field and --snmp-va

#4 Post by mstbone67a » Sun Mar 04, 2012 2:17 am

Pretty slick!! Loving this.

I could not figure out how to do multiple regex maybe it is due to it being 1am. /shrug

I was trying to look for Gi or PO in the ifDescr AND GMPLS in ifAlias
meaning
any Gigabit and POS interface with GMPLS


[[email protected] cli]$ ./add_graphs.php --graph-type=ds --graph-template-id=281 --host-id=2117 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifDescr --snmp-value-regex='^Gi|PO^' --snmp-field=ifAlias --snmp-value-regex='GMPLS'
ERROR: Could not find snmp-field ifDescr,ifAlias (^Gi|PO^GMPLS) for host-id 2117 (10.13.250.33)
Try --host-id=2117 --list-snmp-fields

or even
./add_graphs.php --graph-type=ds --graph-template-id=281 --host-id=2117 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifDescr --snmp-value-regex='Gi|PO' --snmp-field=ifAlias --snmp-value-regex='GMPLS'

But no go I must have been using it wrong.

I can't load Automat8 yet on this system due to it being so heavily used.


This did work
[[email protected] cli]$ ./add_graphs.php --graph-type=ds --graph-template-id=281 --host-id=1307 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifDescr --snmp-value-regex='Gi' --snmp-field=ifAlias --snmp-value-regex='GMPLS'

But I just went back to using the following so I got any interface with GMPLS in the description
[[email protected] cli]$ ./add_graphs.php --graph-type=ds --graph-template-id=281 --host-id=1307 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifAlias --snmp-value-regex='GMPLS'

tsalle
Posts: 7
Joined: Thu Apr 28, 2011 3:37 am

Re: add_graphs.php with multiples --snmp-field and --snmp-va

#5 Post by tsalle » Wed Mar 07, 2012 8:25 am

mstbone67a wrote:Pretty slick!! Loving this.

But I just went back to using the following so I got any interface with GMPLS in the description
[[email protected] cli]$ ./add_graphs.php --graph-type=ds --graph-template-id=281 --host-id=1307 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifAlias --snmp-value-regex='GMPLS'
Yeah, cou can only pass the --snmp-field and --snmp-value-regex and one time !

I've received a private message about this patch, but can't read it :( "You are not authorised to read private messages."

mstbone67a
Posts: 24
Joined: Mon Sep 21, 2009 9:31 am

Re: add_graphs.php with multiples --snmp-field and --snmp-va

#6 Post by mstbone67a » Mon Mar 19, 2012 12:49 pm

that was my pm. just to check this thread.

so anyway to pass multiple strings in the regex? thinking I am just not using it correctly.

Say i wanted to search for "GMPLS" or "sl-pe"

tsalle
Posts: 7
Joined: Thu Apr 28, 2011 3:37 am

Re: add_graphs.php with multiples --snmp-field and --snmp-va

#7 Post by tsalle » Thu Jul 26, 2012 8:44 am

mstbone67a wrote:that was my pm. just to check this thread.

so anyway to pass multiple strings in the regex? thinking I am just not using it correctly.

Say i wanted to search for "GMPLS" or "sl-pe"
You can use the | for multiple regex :

example : "GMPLS|sl-pe"

Post Reply