#!/usr/bin/python
# -*- coding: utf-8 -*-
# kate: space-indent on; indent-width 4; replace-tabs on;

"""
 *  Copyright (C) 2011-2016, it-novum GmbH <community@openattic.org>
 *
 *  openATTIC is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2.
 *
 *  This package is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
"""

import sys
sys.stdout = open("/tmp/notify.log", "a")
sys.stderr = sys.stdout

import os
import dbus

from optparse import OptionParser

print "ohai notify"

parser = OptionParser()

parser.add_option( "-d", "--dbus",
    help="DBus service to connect to.",
    default="org.openattic.systemd"
    )

options, progargs = parser.parse_args()

env = {}

for key, value in os.environ.items():
    if "_" in key:
        nagios, variable = key.split("_", 1)
        if nagios == "NAGIOS":
            env[variable] = value

import json
print json.dumps(env, indent=4)
dbus.SystemBus().get_object(options.dbus, "/nagios").notify(env)
