コード例 #1
0
 def __init__(self, snmpAgentInfo):
     Thread.__init__(self)
     self.storage = SnmpMonitorStorage(snmpAgentInfo)
     self.snmpAgentInfo = snmpAgentInfo
     self.previous = dict()
     self.running = True
     self.start()
コード例 #2
0
 def __init__(self, snmpAgentInfo):
     Thread.__init__(self)
     self.notificationManager = SnmpNotificationManager(snmpAgentInfo)
     self.storage = SnmpMonitorStorage(snmpAgentInfo)
     self.agent = snmpAgentInfo
     self.running = True
     self.start()
コード例 #3
0
 def __init__(self, snmpAgentInfo):
     Thread.__init__(self)
     self.notificationManager = SnmpNotificationManager(snmpAgentInfo)
     self.detector = AberrantBehaviorDetector(snmpAgentInfo)
     self.storage = SnmpMonitorStorage(snmpAgentInfo)
     self.agent = snmpAgentInfo
     self.previous = dict()
     self.running = True
     self.start()
コード例 #4
0
class SnmpAgentMonitor(Thread):

    def __init__(self, snmpAgentInfo):
        Thread.__init__(self)
        self.storage = SnmpMonitorStorage(snmpAgentInfo)
        self.snmpAgentInfo = snmpAgentInfo
        self.running = True
        self.start()

    def stop(self):
        self.running = False

    def __del__(self):
        self.stop()

    def run(self):
        while self.running:
            try:
                updateValues = dict()

                responses = snmpQuery.snmpGet(
                        self.snmpAgentInfo.snmpVersion,
                        self.snmpAgentInfo.community,
                        self.snmpAgentInfo.address,
                        self.snmpAgentInfo.port,
                        appConstants.SIMPLE_OIDS
                    )
                if responses:
                    for oid in responses:
                        name = appConstants.OID_TO_NAME[oid]
                        updateValues[name] = responses[oid]
            
                for oid in appConstants.COMPLEX_OIDS:
                    responses = snmpQuery.snmpWalk(
                            self.snmpAgentInfo.snmpVersion,
                            self.snmpAgentInfo.community,
                            self.snmpAgentInfo.address,
                            self.snmpAgentInfo.port,
                            oid
                        )

                    if responses:
                        total = 0
                        for key in responses:
                            total += int(responses[key])
                        name = appConstants.OID_TO_NAME[oid]
                        updateValues[name] = str(total)

                self.storage.updateDatabase(updateValues)
                
                time.sleep(appConstants.MONITOR_FREQ)                

            except:
                logging.error('Exception while monitoring %s : %s',
                    self.snmpAgentInfo, sys.exc_info())
                self.stop()
コード例 #5
0
class SnmpAgentMonitor(Thread):
    def __init__(self, snmpAgentInfo):
        Thread.__init__(self)
        self.storage = SnmpMonitorStorage(snmpAgentInfo)
        self.agent = snmpAgentInfo
        self.running = True
        self.start()

    def setGroup(self, group):
        self.group = group

    def stop(self):
        self.running = False

    def __del__(self):
        self.stop()

    def run(self):
        while self.running:
            try:
                updates = dict()

                updates[
                    rrdConstants.DS_MEMORY] = perf.getMemoryUsagePercentage(
                        self.agent)
                updates[rrdConstants.DS_DISK] = perf.getDiskUsagePercentage(
                    self.agent)
                updates[rrdConstants.DS_CPU] = perf.getAverageProcessorLoad(
                    self.agent)

                self.storage.updateDatabase(updates)

                time.sleep(appConstants.MONITOR_FREQ)

            except:
                logging.error('Exception while monitoring %s : %s', self.agent,
                              sys.exc_info())
                self.stop()

        self.group.stageRemoval(self.agent)
        self.group = None
コード例 #6
0
class SnmpAgentMonitor(Thread):
    def __init__(self, snmpAgentInfo):
        Thread.__init__(self)
        self.notificationManager = SnmpNotificationManager(snmpAgentInfo)
        self.storage = SnmpMonitorStorage(snmpAgentInfo)
        self.agent = snmpAgentInfo
        self.running = True
        self.start()

    def stop(self):
        self.running = False

    def __del__(self):
        self.stop()

    def run(self):
        while self.running:
            try:
                updates = dict()

                updates[
                    rrdConstants.DS_MEMORY] = perf.getMemoryUsagePercentage(
                        self.agent)
                updates[rrdConstants.DS_DISK] = perf.getDiskUsagePercentage(
                    self.agent)
                updates[rrdConstants.DS_CPU] = perf.getAverageProcessorLoad(
                    self.agent)

                notificationLevel = self.storage.updateDatabase(updates)

                if notificationLevel == rrdConstants.READY:
                    self.notificationManager.sendReadyNotification()
                elif notificationLevel == rrdConstants.SET:
                    self.notificationManager.sendSetNotification()
                elif notificationLevel == rrdConstants.GO:
                    self.notificationManager.sendGoNotification()

                self.notificationManager.flushPending()

                time.sleep(appConstants.MONITOR_FREQ)

            except:
                logging.error('Exception while monitoring %s : %s', self.agent,
                              sys.exc_info())
                self.stop()
コード例 #7
0
class SnmpAgentMonitor(Thread):
    def __init__(self, snmpAgentInfo):
        Thread.__init__(self)
        self.notificationManager = SnmpNotificationManager(snmpAgentInfo)
        self.detector = AberrantBehaviorDetector(snmpAgentInfo)
        self.storage = SnmpMonitorStorage(snmpAgentInfo)
        self.agent = snmpAgentInfo
        self.previous = dict()
        self.running = True
        self.start()

    def setGroup(self, group):
        self.group = group

    def stop(self):
        self.running = False

    def __del__(self):
        self.stop()

    def run(self):
        try:
            # Information to compute deltas.
            self.previous['ifInOctets'] = self.queryInterface()

            self.previous['time'] = int(time.time())
            self.previous['time'] -= appConstants.MONITOR_FREQ

            while self.running:
                updates = dict()

                updates[rrdConstants.DS_CPU] = perf.getAverageProcessorLoad(
                    self.agent)
                updates[rrdConstants.DS_NETWORK] = self.computeBandwidth()

                self.storage.updateDatabase(updates)

                if self.detector.update(updates):
                    self.notificationManager.sendNotification()
                self.notificationManager.flushPending()

                time.sleep(appConstants.MONITOR_FREQ)

        except:
            logging.error('Exception while monitoring %s : %s', self.agent,
                          sys.exc_info())
            self.stop()

        self.group.stageRemoval(self.agent)
        self.group = None

    def queryInterface(self):
        # Get the device's ifTable
        query = snmpQuery.snmpWalk(self.agent.snmpVersion,
                                   self.agent.community, self.agent.address,
                                   self.agent.port, '1.3.6.1.2.1.2.2.1')

        # Loop through the entries to find the first
        # interface ot type ethernetCsmacd (6)
        ifIndex = None

        for key, value in query.items():
            # Check if this is an ifType column.
            if key.startswith('1.3.6.1.2.1.2.2.1.3.'):
                if not value == '6':
                    continue
                # The ifIndex is the las item on the OID.
                ifIndex = key.split('.')[-1]
                break

        if not ifIndex:
            return None

        ifInOctets = int(query['1.3.6.1.2.1.2.2.1.10.' + ifIndex])

        return ifInOctets

    def computeBandwidth(self):
        # Compute average speed using deltas
        # and a formula similar to Cisco's.
        ifInOctets = self.queryInterface()
        now = int(time.time())

        if not ifInOctets:
            return None

        deltaIn = ifInOctets - self.previous['ifInOctets']
        deltaTime = now - self.previous['time']

        inBandwidth = (deltaIn * 8) / deltaTime

        # Store the current values for the next iteration.
        self.previous['ifInOctets'] = ifInOctets
        self.previous['time'] = now

        return inBandwidth