I want to use the “| grep” command to reduce the output of a plugin:
" “./plugin -command1 A -command2 B” | grep “Example” "
In my case it’s about the nagios-check Check_iDrac_for_Dell where I want to use the SENSOR option to get the temperature information of CPU and SYSTEM. My problem is that I want to define two Checks, where one checks the CPU with a certain warning/critical-temperature range and one checks the System with another temperature range. To get an idea what I’m talking about, here is my input and output:
CPU1 Temp: 52.0(!) C ENABLED/OK
CPU2 Temp: 58.0(!) C ENABLED/OK
System Board Inlet Temp: 23.0 C ENABLED/OK
System Board Exhaust Temp: 39.0(!) C ENABLED/OK
The module itself cannot specify between CPU and System-Sensor. My problem would be solved if i could use after the the command " | grep “CPU” ". But I don’t know how to define a CheckCommand like this. My idea for the CheckCommand and Service was this
you can use a wrapperscript, if you don’t want, or can’t edit your check directly (f.e. its compiled code or you want updatesafety):
Example wrapper for check_snmp to show correct temprature if comma/dot is missing:
grep will not only reduce the output, it will also override the exit state. A better solution would be to write a small shell wrapper which takes all the parameters, greps for content, and then sets the exit state accordingly.
Since I always need to Google that with Bash, I’ve just created such a script for your convenience.
#Converting Number
tempStringResult = re.search(‘CPU1’, snmp_output)
if tempStringResult is not None:
tempString = tempStringResult.group(0)
new_snmp_output=snmp_output.split(“\n”,2)[2];
else:
new_snmp_output=snmp_output
The problematic part is the --temp-warn/crit command. The foor-loop only accepts commands with one -. How can I give the for-loop the option that it takes also these commands with the right syntax, e.g. --temp-warn=25,45?
HI, actually i just started with python, so my skills are a little limited
I’am building the argument line string for check_snmp with this line in the code: arguments += "-" + arg + " " + getattr(args, arg) + " "
because arg gives the argument without the “-”. maybe change “-” to “–” would help, but than you need to determine if a “–” or a “-” is needed. I’am pretty sure there is a better solution around, maybe a python veteran has a better idea. For the debugging you could “print(arg)” whats stored in the “arg” variable to see whats the problem.