Beispiel #1
0
    def generate_events(self):
        """
        Report state changes to event engine.
        """
        _logger.debug("Checks which hosts didn't answer")
        answers = self.pinger.results()
        for ip, rtt in answers:
            # rtt = round trip time (-1 => host didn't reply)
            netboxid = self.ip_to_netboxid.get(ip)
            self.replies[netboxid].push(rtt)
            netbox = self.netboxmap[netboxid]
            if rtt != -1:
                statistics.update(netbox.sysname, 'N', 'UP', rtt)
            else:
                # ugly...
                statistics.update(netbox.sysname, 'N', 'DOWN', 5)

        down_now = []
        # Find out which netboxes to consider down
        for (netboxid, replies) in self.replies.items():
            if replies[:self._nrping] == [-1] * self._nrping:
                down_now.append(netboxid)

        _logger.debug("No answer from %i hosts", len(down_now))
        # Detect state changes since last run
        report_down = set(down_now) - set(self.down)
        report_up = set(self.down) - set(down_now)
        self.down = down_now

        # Reporting netboxes as down
        _logger.debug("Starts reporting %i hosts as down", len(report_down))
        for netboxid in report_down:
            netbox = self.netboxmap[netboxid]
            new_event = Event(
                None,
                netbox.netboxid,
                None,  # deviceid
                Event.boxState,
                "pping",
                Event.DOWN)
            self.db.new_event(new_event)
            _logger.info("%s marked as down.", netbox)
        # Reporting netboxes as up
        _logger.debug("Starts reporting %i hosts as up", len(report_up))
        for netboxid in report_up:
            try:
                netbox = self.netboxmap[netboxid]
            except:
                _logger.info("Netbox %s is no longer with us...", netboxid)
                continue
            new_event = Event(
                None,
                netbox.netboxid,
                None,  # deviceid
                Event.boxState,
                "pping",
                Event.UP)
            self.db.new_event(new_event)
            _logger.info("%s marked as up.", netbox)
Beispiel #2
0
 def updateRrd(self):
     try:
         statistics.update(self.getNetboxid(), self.getSysname(), 'N',
                           self.getStatus(), self.getResponsetime(),
                           self.getServiceid(), self.getType())
     except Exception, e:
         service = "%s:%s" % (self.getSysname(), self.getType())
         debug("rrd update failed for %s [%s]" % (service, e), 3)
 def update_stats(self):
     """Send an updated metric to the Graphite backend"""
     try:
         statistics.update(self.netboxid, self.sysname, 'N', self.status,
                           self.response_time, self.serviceid,
                           self.get_type())
     except Exception as err:  # pylint: disable=broad-except
         service = "%s:%s" % (self.sysname, self.get_type())
         LOGGER.error("statistics update failed for %s [%s]", service, err)
 def updateRrd(self):
     try:
         statistics.update(self.getNetboxid(),
                self.getSysname(),
                'N',
                self.getStatus(),
                self.getResponsetime(),
                self.getServiceid(),
                self.getType()
                )
     except Exception, e:
         service = "%s:%s" % (self.getSysname(), self.getType())
         debug("rrd update failed for %s [%s]" % (service, e), 3)
Beispiel #5
0
    def generateEvents(self):
        """
        Report state changes to event engine.
        """
        debug.debug("Checks which hosts didn't answer",7)
        answers = self.pinger.results()
        for ip, rtt in answers:
            # rtt = round trip time (-1 => host didn't reply)
            netboxid = self.ipToNetboxid.get(ip)
            self.replies[netboxid].push(rtt)
            netbox = self.netboxmap[netboxid]
            if rtt != -1:
                statistics.update(netbox.netboxid, netbox.sysname, 'N', 'UP',
                                  rtt)
            else:
                # ugly...
                statistics.update(netbox.netboxid, netbox.sysname, 'N', 'DOWN',
                                  5)

        downNow = []
        # Find out which netboxes to consider down
        for (netboxid, replies) in self.replies.items():
            if replies[:self._nrping] == [-1]*self._nrping:
                downNow.append(netboxid)
        
        debug.debug("No answer from %i hosts" %len(downNow),7)
        # Detect state changes since last run
        reportDown = filter(lambda x: x not in self.down, downNow)
        reportUp = filter(lambda x: x not in downNow, self.down)
        self.down = downNow

        # Reporting netboxes as down
        debug.debug("Starts reporting %i hosts as down" % len(reportDown),7)
        for netboxid in reportDown:
            netbox = self.netboxmap[netboxid]
            newEvent = Event(None,
                             netbox.netboxid,
                             netbox.deviceid,
                             Event.boxState,
                             "pping",
                             Event.DOWN
                             )
            self.db.newEvent(newEvent)
            debug.debug("%s marked as down." % netbox)
        # Reporting netboxes as up
        debug.debug("Starts reporting %i hosts as up" % len(reportUp),7)
        for netboxid in reportUp:
            try:
                netbox = self.netboxmap[netboxid]
            except:
                debug.debug("Netbox %s is no longer with us..." % netboxid)
                continue
            newEvent = Event(None,
                             netbox.netboxid,
                             netbox.deviceid,
                             Event.boxState,
                             "pping",
                             Event.UP
                             )
            self.db.newEvent(newEvent)
            debug.debug( "%s marked as up." % netbox)