def _getAgentHDDLin(self, hostname): if not hostname in self._agents: return try: eIndi, eStatus, eIndex, vBinds = next( getCmd(SnmpEngine(), CommunityData(self._agents[hostname].getCommunity()), UdpTransportTarget((hostname, self._agents[hostname].getPort())), ContextData(), ObjectType(ObjectIdentity(self._querys['UCD'] + self._querys['HDDSize'])), ObjectType(ObjectIdentity(self._querys['UCD'] + self._querys['HDDUse'])),) ) if eIndi: print eIndi #self._agents[hostname].setStatus(False) elif eStatus: print eIndex, eStatus #self._agents[hostname].setStatus(False) else: i = 0 for varBind in vBinds: a = [x.prettyPrint() for x in varBind] if i == 0: self._agents[hostname].setHDDSize(int(a[1])) elif i == 1: self._agents[hostname].setHDDUse(int(a[1])) fn = self._names[7] nRRD = self._fname[fn].format(hostname, 'rrd') value = ':'.join(['N', a[1]]) try: ret = rrdtool.update(nRRD, value) except: print 'problem update HDD _getAgentHDDLin' if self._limits['HDD'] is None: continue label = None for limit in self._labels: valLimit = self._agents[hostname].getHDDSize() * self._limits['HDD'][limit] if valLimit < self._agents[hostname].getHDDUse(): label = limit if label is not None: noti = Notification(hostname, 'HDD', label, self._limits['HDD'][label], self._agents[hostname].getHDDUse(), self._fname[fn].format(hostname, 'png')) flag = True if 0 < len(self._notifications[hostname]['HDD']): last = self._notifications[hostname]['HDD'][-1] diff = noti.getTimeReport() - last.getTimeReport() if diff < self._limits['Time']:# and last.getLabel() == noti.getLabel(): flag = False if flag: self._notifications[hostname]['HDD'].append(noti) self._newNotification.append(noti.getReport()) self._sendMail(noti) else: print 'error HDD', i i += 1 except: print 'Exception _getAgentHDDLin'
def _getCPUsUse(self, hostname): if not hostname in self._agents: return try: walk = nextCmd(SnmpEngine(), CommunityData(self._agents[hostname].getCommunity()), UdpTransportTarget((hostname, self._agents[hostname].getPort())), ContextData(), ObjectType(ObjectIdentity(self._querys['MIB'] + self._querys['CPUUse'])), ) cpus = self._agents[hostname].getNumCPUs() cpusUse = [0] * cpus for i in range(cpus): eIndi, eStatus, eIndex, vBinds = next(walk) if eIndi: print eIndi, i continue elif eStatus: print eIndex, eStatus, i continue else: for varBind in vBinds: a = [x.prettyPrint() for x in varBind] cpusUse[i] = int(a[1]) fn = self._names[6] nRRD = self._fname[fn].format(hostname, i, 'rrd') value = ':'.join(['N', a[1]]) if True:#try: ret = rrdtool.update(nRRD, value) else:#except: print 'problem update cpu _getCPUsUse' if self._limits['CPU'] is None: continue label = None for limit in self._labels: valLimit = self._limits['CPU'][limit] if valLimit < cpusUse[i]: label = limit if label is not None: noti = Notification(hostname, 'CPU ' + str(i+1), label, self._limits['CPU'][label], cpusUse[i], self._fname[fn].format(hostname, i, 'png')) if not i in self._notifications[hostname]['CPU']: self._notifications[hostname]['CPU'][i] = [] self._notifications[hostname]['CPU'][i].append(noti) self._newNotification.append(noti.getReport()) self._sendMail(noti) else: last = self._notifications[hostname]['CPU'][i][-1] diff = noti.getTimeReport() - last.getTimeReport() if self._limits['Time'] < diff :#or last.getLabel() != noti.getLabel(): self._notifications[hostname]['CPU'][i].append(noti) self._newNotification.append(noti.getReport()) self._sendMail(noti) self._agents[hostname].setCPUsUse(cpusUse) except (KeyError, rrdtool.OperationalError) as e: print 'something wrong _getPerCPUs'