def system(self): system_info_dict = {} memory = system_info_collector.get_memory_info() cpu = system_info_collector.get_cpu_utilization() loadavg = system_info_collector.get_load_average() disk = system_info_collector.get_disk_usage() network = system_info_collector.get_network_traffic() uptime = system_info_collector.get_uptime() if memory != False: system_info_dict['memory'] = memory if cpu != False: system_info_dict['cpu'] = cpu if loadavg != False: system_info_dict['loadavg'] = loadavg if disk != False: system_info_dict['disk'] = disk if network != False: system_info_dict['network'] = network if uptime != False: system_info_dict['uptime'] = uptime system_info_dict['time'] = unix_utc_now() return system_info_dict
def save_occurence(self, alerts): # Format: {'cpu': [{'alert_on': 2.6899999999999977, 'rule': '4f55da92925d75158d0001e0'}}]} for key, values_list in alerts.iteritems(): for value in values_list: alert_on = value.get('alert_on', None) rule_id = value.get('rule', None) metric_type = value.get('metric_type', None) if alert_on is not None: alert_on = "{0:.2f}".format(float(alert_on)) alert = self.get_by_id(rule_id) history = alert.get('history', []) threshold = alert.get('threshold', 1) last_trigger = alert.get('last_trigger', 1) trigger = True if int(last_trigger) >= int(threshold) else False history.append({"value": alert_on, "time": unix_utc_now(), "trigger": trigger, "metric_type": metric_type}) # Reset the last trigger count if trigger is True: last_trigger = 1 else: last_trigger = last_trigger+1 alert_id = self.mongo.get_object_id(rule_id) self.collection.update({"_id": alert_id}, {"$set": {"history": history, "last_trigger": last_trigger}})
def store_process_entries(self, data): self.server_update_processes(data.keys()) collection = self.mongo.get_collection('processes') data["time"] = unix_utc_now() collection.insert(data) collection.ensure_index([('time', self.desc)]) # Check for alerts server_alerter.check(data=data, alert_type='process')
def processes(self): process_checks = process_info_collector.process_list() process_info_dict = {} for process in process_checks: command = process["command"] command = command.replace(".", "") del process["command"] process_info_dict[command] = process process_info_dict['time'] = unix_utc_now() return process_info_dict
def store_system_entries(self, data): data["time"] = unix_utc_now() self.server_update_disk_volumes(data.get('disk', None)) self.server_update_network_interfaces(data.get('network', None)) self.server_update_last_check(data['time']) collection = self.mongo.get_collection('system') collection.insert(data) collection.ensure_index([('time', self.desc)]) # Check for alerts server_alerter.check(data=data, alert_type='server')
def save_occurence(self, alerts): # Format: {'cpu': [{'alert_on': 2.6899999999999977, 'rule': '4f55da92925d75158d0001e0'}}]} for key, values_list in alerts.iteritems(): for value in values_list: alert_on = value.get('alert_on', None) rule_id = value.get('rule', None) metric_type = value.get('metric_type', None) if alert_on is not None: alert_on = "{0:.2f}".format(float(alert_on)) alert = self.get_by_id(rule_id) history = alert.get('history', []) threshold = alert.get('threshold', 1) last_trigger = alert.get('last_trigger', 1) trigger = True if int(last_trigger) >= int( threshold) else False history.append({ "value": alert_on, "time": unix_utc_now(), "trigger": trigger, "metric_type": metric_type }) # Reset the last trigger count if trigger is True: last_trigger = 1 else: last_trigger = last_trigger + 1 alert_id = self.mongo.get_object_id(rule_id) self.collection.update({"_id": alert_id}, { "$set": { "history": history, "last_trigger": last_trigger } })