def xmlrpc_cancelDowntime(self, key, delay=None):

        key = key.strip()

        if ':' in key:
            try:
                timestamp, key = key.split(':', 1)
                assert int(timestamp) and int(key)
            except:
                raise xmlrpc.Fault(1, "Invalid downtime key: %r" % key)

            status = self._status(('hostdowntime', 'servicedowntime'),
                                  {'entry_time': timestamp})
        else:
            status = self._status(('hostdowntime', 'servicedowntime'))

        regex = re.compile('\skey:%s(\s|$)' % key)
        match = lambda x: regex.search(x['comment'])

        commands = set()
        commands.update(('DEL_HOST_DOWNTIME', x['downtime_id'])
                for x in status['hostdowntime'] if match(x))
        commands.update(('DEL_SVC_DOWNTIME', x['downtime_id'])
                for x in status['servicedowntime'] if match(x))

        if not commands:
            return 0

        del status

        # We want to run later or at shutdown, whichever comes first.
        # This really seems like a thing that should be in twisted
        # but I didn't see anything. Oh well.
        calls = {'timer': None, 'shutdown': None}

        def do_cmd(force=False):
            calls['shutdown'] = None
            calls['timer'] = None
            log.info("Canceling %s downtimes in Nagios" % len(commands))
            self._cmdobj.cmdlist(None, commands, force)

        def do_timer():
            reactor.removeSystemEventTrigger(calls['shutdown'])
            do_cmd()

        def do_shutdown():
            calls['timer'].cancel()
            # This should not abort the daemon shutdown
            try:
                do_cmd(force=True)
            except:
                fail = failure.failure()
                log.error(fail)

        if delay:
            calls['timer'] = reactor.callLater(delay, do_timer)
            calls['shutdown'] = reactor.addSystemEventTrigger(
                    'before', 'shutdown', do_shutdown)
        else:
            do_cmd()

        return len(commands)
Cancel a requested service or host downtime.
dataset/ETHPy150Open marineam/nagcat/python/nagcat/nagios_api.py/NagiosXMLRPC.xmlrpc_cancelDowntime