Page 1 of 1

Hostname variable concatenation

Posted: Wed Feb 24, 2016 10:57 am
by rfischer
Hello!
I've used Nagios for around a year. Took over the one running in the office, and I've learned a lot since then.

On to brass tacks: I need to monitor the bandwidth on multiple network devices (switches, routers, load balancers), so I read some of the documentation and setup mrtg to handle the data acquisition.
I've been told that we need to monitor the special interfaces (PortChannel, VLAN). The way the Nagios documentation recommends I do it is by defining one check per IP per interface, hardcoded:

Code: Select all

define service{
	use			generic-service	; Inherit values from a template
	host_name			linksys-srw224p
	service_description	Port 1 Bandwidth Usage
	check_command		check_local_mrtgtraf!/var/lib/mrtg/192.168.1.253_1.log!AVG!1000000,2000000!5000000,5000000!10
	}
This is not useful to me, as I'd have to generate over 100 service definitions per network device.

Is there a way to concatenate the hostname in the command?
So that check_command would end up like this:

Code: Select all

check_local_mrtgtraf!/var/lib/mrtg/$HOSTNAME$_1.log!AVG!1000000,2000000!5000000,5000000!10

Re: Hostname variable concatenation

Posted: Wed Feb 24, 2016 11:00 am
by tmcdonald
That's exactly how you would do it, that or use $HOSTADDRESS$ which might make more sense in case the name is not an IP. Also, the quotes are not needed.

Re: Hostname variable concatenation

Posted: Wed Feb 24, 2016 11:11 am
by rfischer
Excellent, thanks for your reply.

I'd become used to bash concatenation where I'd need to invoke obscure stuff to make whatever I was working on execute as I wanted it to. I wasn't really sure how Nagios handled it.

Re: Hostname variable concatenation

Posted: Wed Feb 24, 2016 11:17 am
by eloyd
Nagios Macros are your friend. A complete list of what they are and when they are valid is available at https://assets.nagios.com/downloads/nag ... olist.html

Re: Hostname variable concatenation

Posted: Wed Feb 24, 2016 6:05 pm
by hsmith
Thanks, Eric. Did you have any more questions, OP?