Attempting to execute bash script stored in Service Meta variable, referenced in command_line

Mike Lindsey mike-nagios at 5dninja.net
Fri Jul 8 05:39:14 CEST 2011


I know there are reasons why you might not want to do this (code 
injection, etc) but I'm more concerned at the moment with what I can 
solve with it, than what could be broken with it.

What I'm trying to do, is have certain services which have variable 
time-based thresholds.  So, during business hours some check might have 
a critical threshold of 200, and 50 otherwise; in a manner flexible 
enough for a different threshold for each hour of the week - if needed.  
I want to be able to do this, without having to write the dozen or two 
different scripts, in four or five different languages, in my env, that 
this would be useful for.

In my service definition I have:
define service {
         service_description ip_corpus_mailflow_rate__test
         check_command       
mailflow_rate!1200!db!table!$$NAGIOS__SERVICEWARN!$$NAGIOS__SERVICECRIT

         _CRIT               $((/path/_slice_threshold.sh CRIT))

         _CRITTHRESH         50 50 50 50 50 50 200 200 200 200 200 200 
200 200 200 200 200 200 200 50 50 50 50 50 50 50 50 50 50 50 200 200 200 
200 200 200 200 200 200 200 200 200 200 50 50 50 50 50 50 50 50 50 50 50 
200 200 200 200 200 200 200 200 200 200 200 200 200 50 50 50 50 50 50 50 
50 50 50 50 200 200 200 200 200 200 200 200 200 200 200 200 200 50 50 50 
50 50 50 50 50 50 50 50 200 200 200 200 200 200 200 200 200 200 200 200 
200 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 
50 50 50 50 50 50

         _WARN               $((/path/_slice_threshold.sh WARN))

         _WARNTHRESH         200 200 200 200 200 200 600 600 600 600 600 
600 600 600 600 600 600 600 600 200 200 200 200 200 200 200 200 200 200 
200 600 600 600 600 600 600 600 600 600 600 600 600 600 200 200 200 200 
200 200 200 200 200 200 200 600 600 600 600 600 600 600 600 600 600 600 
600 600 200 200 200 200 200 200 200 200 200 200 200 600 600 600 600 600 
600 600 600 600 600 600 600 600 200 200 200 200 200 200 200 200 200 200 
200 600 600 600 600 600 600 600 600 600 600 600 600 600 200 200 200 200 
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 
200 200 200 200 200 200 200 200 200 200 200 200 200
}

My command definition is:
define command {
         command_name        ip_check_corpus_mailflow_rate
         command_line        bash -c '$USER5$/mailflow_rate.py -H 
$HOSTADDRESS$ -u $USER17$ -p $USER10$ -s "$ARG1$" -d "$ARG2$" -t 
"$ARG3$" -w "$ARG4$" -c "$ARG5$" 2>&1'
}

The command gets expanded, pretty much as I expect, but bash doesn't 
expand the inner variable.  I've tried both $(()) and ``...

Debug log output:
Processing part: '/mailflow_rate.py -H '
Not currently in macro.  Running output (98): 'bash -c 
'mailflow_rate.py  -H '
Uncleaned macro.  Running output (133): 'bash -c 'mailflow_rate.py -H 
xxhostxx'
Not currently in macro.  Running output (137): 'bash -c 
'mailflow_rate.py -H xxhostxx -u '
Uncleaned macro.  Running output (143): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user'
Not currently in macro.  Running output (147): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p '
Uncleaned macro.  Running output (154): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user -p xxxx'
Not currently in macro.  Running output (159): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p xxxx -s "'
Uncleaned macro.  Running output (163): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user -p xxxx -s "1200'
Not currently in macro.  Running output (169): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p xxxx -s "1200" -d "'
Uncleaned macro.  Running output (175): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user -p xxxx -s "1200" -d "db'
Not currently in macro.  Running output (181): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p xxxx -s "1200" -d "db" -t "'
Uncleaned macro.  Running output (185): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user -p xxxx -s "1200" -d "db" -t "table'
Not currently in macro.  Running output (191): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p xxxx -s "1200" -d "db" -t 
"table" -w "'
Uncleaned macro.  Running output (211): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user -p xxxx -s "1200" -d "db" -t "table" -w 
"$NAGIOS__SERVICEWARN'
Not currently in macro.  Running output (217): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p xxxx -s "1200" -d "db" -t 
"table" -w "$NAGIOS__SERVICEWARN" -c "'
Uncleaned macro.  Running output (237): 'bash -c 'mailflow_rate.py -H 
xxhostxx -u user -p xxxx -s "1200" -d "db" -t "table" -w 
"$NAGIOS__SERVICEWARN" -c "$NAGIOS__SERVICECRIT'
Not currently in macro.  Running output (244): 'bash -c 
'mailflow_rate.py -H xxhostxx -u user -p xxxx -s "1200" -d "db" -t 
"table" -w "$NAGIOS__SERVICEWARN" -c "$NAGIOS__SERVICECRIT" 2>&1''
Done.  Final output: 'bash -c 'mailflow_rate.py -H xxhostxx -u user -p 
xxxx -s "1200" -d "db" -t "table" -w "$NAGIOS__SERVICEWARN" -c 
"$NAGIOS__SERVICECRIT" 2>&1''

Short Output: Usage: mailflow_rate.py [options]
Long Output:  \nmailflow_rate.py: error: option -w: invalid integer 
value: '$((/path/_slice_threshold.sh WARN))'\n



So, the final command has the right environment macros, and it does pull 
the string I expect out of the first service meta variable, but bash 
doesn't do the command substitution, just hands the unsubstituted string 
off to the poller script.

Any ideas on how I can get this working right?

--
Mike Lindsey


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list