Hostname variable concatenation

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rfischer
Posts: 2
Joined: Wed Feb 24, 2016 10:32 am

Hostname variable concatenation

Post 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
Last edited by rfischer on Wed Feb 24, 2016 11:02 am, edited 1 time in total.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Hostname variable concatenation

Post 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.
Former Nagios employee
rfischer
Posts: 2
Joined: Wed Feb 24, 2016 10:32 am

Re: Hostname variable concatenation

Post 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.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Hostname variable concatenation

Post 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
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Hostname variable concatenation

Post by hsmith »

Thanks, Eric. Did you have any more questions, OP?
Former Nagios Employee.
me.
Locked