I want to get the number of openvpn user via SNMP and view in icinga2.
I got result with a python scripts(2016 By Christian Stankowic stdevel (Christian Stankowic) · GitHub)
My guess:
As you are wrapping the check script with a shell script, you are getting back the exit code of that wrapper script instead of the check script.
So you would need to make the wrapper check for the exit code of the check script and use that instead of the wrappers own exit code.
I agree with this. I’m not saying anyone here doesn’t know bash, but if someone happens to stumble upon this in the future who doesn’t, you can get the exit code with $? and do any additional logic checking if you wish, or simply exit after.
$? gets the exit code of the last run command, so will needed to be checked after the bash script executes the check command.
Should be as simple as
#! /bin/bash
python /etc/snmp/scripts/check_ovpn_users.py -f /var/log/openvpn-status.log -P
exit # When no parameter is given to exit, it will exit with the status code of the last executed command iirc
Note that $? is only valid immediately after the command you want the exit
code from - copy it into another variable straight away and then use that
later when you are ready to exit from your script.
If you have any other commands in between check_snmp and when you use $?, you
will get the result of the last command run before you looked at $?, not the
result of check_snmp.