Commit 22af6c0c authored by Olav Morken's avatar Olav Morken
Browse files

Add option to send result to a Zabbix item.

parent 86fff76d
......@@ -15,6 +15,8 @@ Features
* Timeout on execution (default 60 seconds).
* Send result of operation to a Zabbix item.
......@@ -53,3 +55,15 @@ --name name-of-the-job --device /dev/net/tun --cap-add NET_ADMIN
``` --name name-of-the-job --timeout=30
### Report status to Zabbix
This reports the result of the job to our Zabbix server.
It is added to the item with key "someitem" on the host "".
"someitem" must be a "Zabbix trapper" item, with type "Numeric (unsigned)".
The value is reported as "1" on success and "0" on failure.
``` --name name-of-the-job
......@@ -244,6 +244,33 @@ class _DockerRunner(object):
# Remove the container name, to mark the container as not running.
self.container_name = None
def _parse_zabbix_item(item):
host, key = item.split(':', 1)
raise argparse.ArgumentTypeError('Zabbix-item must be on the form HOST:ITEM')
return (host, key)
def _send_zabbix_result(zabbix_item, ok):
if not zabbix_item:
if ok:
value = 1
value = 0
hostname, key = zabbix_item
args = [
'--zabbix-server', '',
'--host', hostname,
'--key', key,
'--value', str(value),
parser = argparse.ArgumentParser()
parser.add_argument('--name', required=True, help="Name of task to run. Mainly used to identify the docker image.")
......@@ -253,10 +280,16 @@ parser.add_argument('--env', action='append', default=[], help="Pass-through for
parser.add_argument('--device', action='append', default=[], help="Pass-through for Docker --device option.")
parser.add_argument('--cap-add', action='append', default=[], help="Pass-through for Docker --cap-add option.")
parser.add_argument('--volume', action='append', default=[], help="Pass-through for Docker --volume option.")
parser.add_argument('--zabbix-item', type=_parse_zabbix_item, metavar='HOST:KEY', help="Zabbix item to report status to.")
parser.add_argument('cmd', nargs='*', help="Command to run in the docker container.")
args = parser.parse_args()
runner = _DockerRunner(args)
runner = _DockerRunner(args)
_send_zabbix_result(args.zabbix_item, runner.retcode == 0)
_send_zabbix_result(args.zabbix_item, False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment