Switch monitor when community string has special chars

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
tonkaUser
Posts: 54
Joined: Tue Nov 28, 2017 10:27 am

Switch monitor when community string has special chars

Post by tonkaUser »

Hi,

Our SNMP community string has special characters (! and &). If we use the wizard to configure Network Switch / Router, then the services do not work and we need to escape special characters. We have 10s of routers/switches to monitor. Each of the port statuses has the port number, so we cannot use Bulk Modification tool.

I want config files to be created with the escaped community string.
I started looking at /usr/local/nagiosxi/html/includes/configwizards/switch/switch.inc.php. Is that the right approach to hack this page so configs are generated correctly? Is there an update that we can take that will escape special chars?

Thanks
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Switch monitor when community string has special chars

Post by tmcdonald »

Take a look at User Macros, muuuuch easier: https://assets.nagios.com/downloads/nag ... Macros.pdf
Former Nagios employee
tonkaUser
Posts: 54
Joined: Tue Nov 28, 2017 10:27 am

Re: Switch monitor when community string has special chars

Post by tonkaUser »

Once I define the community string as a macro (with escaped special chars), how would I tell network wizard to use that when generating the config files?
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Switch monitor when community string has special chars

Post by npolovenko »

@tonkaUser, Yes, you'd define macros in:

Code: Select all

/usr/local/nagios/etc/resource.cfg
$USER7$=User*!name
$USER8$=Pass*!Word
Then restart Nagios and use macros inside the wizard:

Code: Select all

service nagios restart
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
tonkaUser
Posts: 54
Joined: Tue Nov 28, 2017 10:27 am

Re: Switch monitor when community string has special chars

Post by tonkaUser »

Thanks. I added the macro.
Just to confirm. I still need to change /usr/local/nagiosxi/html/includes/configwizards/switch/switch.inc.php:1027 to refer to the newly created macro instead of using $snmpopts['snmpcommunity'] right ?

When I used the wizard, I did not see an option to select a macro for SNMP community string.

Thanks!
tonkaUser
Posts: 54
Joined: Tue Nov 28, 2017 10:27 am

Re: Switch monitor when community string has special chars

Post by tonkaUser »

I changed switch.inc.php to use a user macro and it seems to work. It's a little bit hacky, but I will take it.
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: Switch monitor when community string has special chars

Post by tacolover101 »

tonkaUser wrote:I changed switch.inc.php to use a user macro and it seems to work. It's a little bit hacky, but I will take it.
you went the hacky way bud. that's the great thing about IT - always a solution. :-)

with what the folks above were mentioning - you'd substitute $USER8$ in place of your community string, which Nagios would then parse to reference your comm string.
tonkaUser
Posts: 54
Joined: Tue Nov 28, 2017 10:27 am

Re: Switch monitor when community string has special chars

Post by tonkaUser »

When you said "you'd substitute $USER8$ in place of your community string, " do you mean I can do it using Nagios UI? WOuld I do it when using the wizard or after the wizard was ran to change all the services that were affected?

Thanks!
kyang

Re: Switch monitor when community string has special chars

Post by kyang »

Thanks @tacolover101 for the help!

@tonkaUser, Yes, you would use $USER8$ (which is your community string in resource.cfg)

Typing in $USER8$ in the community string option when using the Network/switch wizard, would use your special characters password.

Let us know if you have any more questions!
tonkaUser
Posts: 54
Joined: Tue Nov 28, 2017 10:27 am

Re: Switch monitor when community string has special chars

Post by tonkaUser »

Thanks. It's clear what you meant now.
I defined $USER9$ as a community string that has all special characters escaped.

I just tried to use $USER9$ as the SNMP community string for the router/switch wizard and the wizard had a problem connecting to the device. I think the issue is that the wizard needs to take SNMP community as-is without escaping special chars when it connects to the device. When the wizard is generating the config files, the special chars should be escaped (e.g. when "check_command" adds the SNMP string, it has to use the escaped version). It feels that the wizard should have smarts to escape any special chars.

Thanks for your help all. It's resolved.
You do not have the required permissions to view the files attached to this post.
Locked