Hello all, newbie here.
I am trying to use Nagios CORE to monitor OSPF and BGP in order to detect failures in redundant fiber and wireless links (which can't be detected by pinging). I have written some scripts to do this, however there is one issue I am running into. Some of the devices have different community strings or telnet (yes very old device) passwords. Right now I have to create a new service for each host to account for the varying passwords, etc. I doubt this is the correct way to do it.
Is it possible for me to store a community string with the host that can be passed to the service so that I can have just one service that can send a different community string for each host that uses the service?
Also, not sure if my wording is easy to understand, so if not, let me know and I can try to clarify. Thanks!
Question about service variables/macros
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Question about service variables/macros
I believe you're looking for custom object variables:
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html
Is that right?
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html
Is that right?
Re: Question about service variables/macros
Thank you jdalrymple. That is exactly what I am looking for.
However I am not sure how to get the host customer variable into a macro for the service. For example:
It's sending a literal string of '$_HOSTCOMMUNITY$' instead of the macro value. Clearly I am just formatting it incorrectly, but I am having a hard time telling how I could be formatting it in the service definition so that the service definition knows to use the macro from the host that is associated with the service definition. Any ideas on where I might be going wrong?
However I am not sure how to get the host customer variable into a macro for the service. For example:
Code: Select all
define host {
host_name test.hostname.com
alias Test Switch 1
display_name test.hostname.com
address 127.0.0.1
parents Main_switch
use router_template
_COMMUNITY mycommunitystring
register 1
}Code: Select all
define service {
host_name test.hostname.com
service_description Check OSPF on Vyatta
display_name vyatta_ospf
use ospf_template
check_command check_vyatta_ospf!$_HOSTCOMMUNITY$
register 1
}-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Question about service variables/macros
That syntax looks proper to me ocolin, and works in my environment:
Maybe check for awkward whitespaces and such?
Code: Select all
define command{
command_name check_dummy
command_line $USER1$/check_dummy $ARG1$ $ARG2$
}
Code: Select all
define host{
use linux-server
host_name localhost
alias localhost
address 127.0.0.1
_COMMUNITY bar
}
Code: Select all
define service{
service_description foobar
use local-service
host_name localhost
check_command check_dummy!0!$_HOSTCOMMUNITY$
}
Re: Question about service variables/macros
Thank you again for your time. I am confused about one thing and it may be why I am having trouble. In your example, the macro in the service check_command is "$_HOSTFOO$", while the variable in the host is "_COMMUNITY".
I don't understand how it knows to replace $_HOSTFOO$ with the value of _COMMUNITY. I would have expected that the check_command would need to be "check_dummy!0!$_HOSTCOMMUNITY".
I mine instead of displaying 'bar' it displays '$' (I set the script to output the argument for the community string. I am going to set it back up and check for white spaces, but am just confused about how those variables and macros connect to each other in yours. Thanks!!
I don't understand how it knows to replace $_HOSTFOO$ with the value of _COMMUNITY. I would have expected that the check_command would need to be "check_dummy!0!$_HOSTCOMMUNITY".
I mine instead of displaying 'bar' it displays '$' (I set the script to output the argument for the community string. I am going to set it back up and check for white spaces, but am just confused about how those variables and macros connect to each other in yours. Thanks!!
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Question about service variables/macros
Oh wow, I apologize for that. You were the victim of me editing code, then editing posts with edited code. I wanted to make sure that my check would work just the same using the exact syntax you used so I made some adjustments on the fly. I'll fix it to what it looks like in a working configuration. I guess to clarify - I'm now using the same exact syntax you're using and it's working for me.
What version of Nagios are you using?
What version of Nagios are you using?
Re: Question about service variables/macros
I re-entered it in the config files and now it's working. I must have had some kind of white-space something that I just could not see. Thank you again so much!