def manage_service_check_result_brok(self, b): data = b.data # Maybe this service is just unknown and without policies, if so, bail out policies = self.svc_dict.get((data["host_name"], data["service_description"]), []) if not policies: return # Ok there are some real policies print "OK POLICIES FOR", (data["host_name"], data["service_description"]), policies perf_data = data["perf_data"] couples = self.get_metric_and_value(perf_data) # If no values, we can exit now if len(couples) == 0: return hname = data["host_name"] # self.illegal_char.sub('_', data['host_name']) # if data['host_name'] in self.host_dict: # customs_datas = self.host_dict[data['host_name']] # if '_GRAPHITE_PRE' in customs_datas: # hname = ".".join((customs_datas['_GRAPHITE_PRE'], hname)) sdesc = data["service_description"] # self.illegal_char.sub('_', data['service_description']) # if (data['host_name'], data['service_description']) in self.svc_dict: # customs_datas = self.svc_dict[(data['host_name'], data['service_description'])] # if '_GRAPHITE_POST' in customs_datas: # desc = ".".join((desc, customs_datas['_GRAPHITE_POST'])) check_time = int(data["last_chk"]) logger.debug( "[Trending broker] Hostname: %s, Desc: %s, check time: %d, perfdata: %s, policies: %s" % (hname, sdesc, check_time, str(perf_data), policies) ) # Ok now the real stuff is here for p in policies: for (metric, value) in couples: try: value = float(value) except ValueError: return if value is not None: print "DUMPING", (metric, value), "for", p sec_from_morning = get_sec_from_morning(check_time) wday = get_wday(check_time) chunk_nb = sec_from_morning / self.chunk_interval # Now update mongodb print "UPDATING DB", wday, chunk_nb, value, hname, sdesc, metric, type(value) self.trender.update_avg( self.col, check_time, wday, chunk_nb, value, hname, sdesc, metric, self.chunk_interval )
def import_csv(reader, _hname, _sdesc, _metric): global hname, sdesc, metric i = 0 for row in reader: if i == 0: # Maybe the first line is an helper line, if so, # use it if len(row) == 3 and row[0].startswith('#'): hname = row[0][1:] sdesc = row[1] metric = row[2] print "IMPORTANT : Removing all entries from ", coll, "for the metric", hname, sdesc, metric coll.remove({'hname': hname, 'sdesc': sdesc, 'metric': metric}) i += 1 _hname = hname _sdesc = sdesc _metric = metric try: _time = int(row[0]) except ValueError: continue try: l1 = float(row[1]) except (IndexError, ValueError): continue # If here we still do not have valid entries, we are not good at all! if not hname or not sdesc or not metric: print "ERROR : missing hostname, or service description or metric name, please check your input file or fill the values as arguments" sys.exit(2) sec_from_morning = get_sec_from_morning(_time) wday = get_wday(_time) chunk_nb = sec_from_morning / CHUNK_INTERVAL # Now update mongodb trender.update_avg(coll, _time, wday, chunk_nb, l1, _hname, _sdesc, _metric, CHUNK_INTERVAL)
def import_csv(reader, _hname, _sdesc, _metric): global hname, sdesc, metric i = 0 for row in reader: if i == 0: # Maybe the first line is an helper line, if so, # use it if len(row) == 3 and row[0].startswith('#'): hname = row[0][1:] sdesc = row[1] metric = row[2] print "IMPORTANT : Removing all entries from ", coll, "for the metric", hname, sdesc, metric coll.remove({'hname':hname, 'sdesc':sdesc, 'metric':metric}) i += 1 _hname = hname _sdesc = sdesc _metric = metric try: _time = int(row[0]) except ValueError: continue try: l1 = float(row[1]) except (IndexError, ValueError): continue # If here we still do not have valid entries, we are not good at all! if not hname or not sdesc or not metric: print "ERROR : missing hostname, or service description or metric name, please check your input file or fill the values as arguments" sys.exit(2) sec_from_morning = get_sec_from_morning(_time) wday = get_wday(_time) chunk_nb = sec_from_morning / CHUNK_INTERVAL # Now update mongodb trender.update_avg(coll, _time, wday, chunk_nb, l1, _hname, _sdesc, _metric, CHUNK_INTERVAL)
# ok open the connexion open_connexion(uri) CHUNK_INTERVAL = int(opts.chunk_interval or '300') trender = Trender(CHUNK_INTERVAL) hname = opts.host_name sdesc = opts.service_description metric = opts.metric prevision = int(opts.prevision or '0') check_time = int(opts.check_time or time.time()) sec_from_morning = get_sec_from_morning(check_time) wday = get_wday(check_time) chunk_nb = sec_from_morning / CHUNK_INTERVAL if prevision == 0: def_warn = '20%' def_crit = '50%' else: def_warn = def_crit = '' warning = opts.warning or def_warn critical = opts.critical or def_crit if warning.endswith('%'): warning = warning[:-1] try: warning = float(warning) except ValueError:
def manage_service_check_result_brok(self, b): data = b.data # Maybe this service is just unknown and without policies, if so, bail out policies = self.svc_dict.get( (data['host_name'], data['service_description']), []) if not policies: return # Ok there are some real policies print "OK POLICIES FOR", (data['host_name'], data['service_description']), policies perf_data = data['perf_data'] couples = self.get_metric_and_value(perf_data) # If no values, we can exit now if len(couples) == 0: return hname = data[ 'host_name'] #self.illegal_char.sub('_', data['host_name']) #if data['host_name'] in self.host_dict: # customs_datas = self.host_dict[data['host_name']] # if '_GRAPHITE_PRE' in customs_datas: # hname = ".".join((customs_datas['_GRAPHITE_PRE'], hname)) sdesc = data[ 'service_description'] #self.illegal_char.sub('_', data['service_description']) #if (data['host_name'], data['service_description']) in self.svc_dict: # customs_datas = self.svc_dict[(data['host_name'], data['service_description'])] # if '_GRAPHITE_POST' in customs_datas: # desc = ".".join((desc, customs_datas['_GRAPHITE_POST'])) check_time = int(data['last_chk']) logger.debug( "[Trending broker] Hostname: %s, Desc: %s, check time: %d, perfdata: %s, policies: %s" % (hname, sdesc, check_time, str(perf_data), policies)) # Ok now the real stuff is here for p in policies: for (metric, d) in couples: value = d['value'] warning = d['warning'] critical = d['critical'] try: value = float(value) except ValueError: return if value is not None: print "DUMPING", (metric, value), "for", p sec_from_morning = get_sec_from_morning(check_time) wday = get_wday(check_time) chunk_nb = sec_from_morning / self.chunk_interval # Now update mongodb print "UPDATING DB", wday, chunk_nb, value, hname, sdesc, metric, type( value), warning, critical self.trender.update_avg(self.col, check_time, wday, chunk_nb, value, hname, sdesc, metric, self.chunk_interval, warning, critical)
uri = opts.uri or 'localhost' # ok open the connexion open_connexion(uri) CHUNK_INTERVAL = int(opts.chunk_interval or '300') trender = Trender(CHUNK_INTERVAL) hname = opts.host_name sdesc = opts.service_description metric = opts.metric prevision = int(opts.prevision or '0') check_time = int(opts.check_time or time.time()) sec_from_morning = get_sec_from_morning(check_time) wday = get_wday(check_time) chunk_nb = sec_from_morning / CHUNK_INTERVAL if prevision == 0: def_warn = '20%' def_crit = '50%' else: def_warn = def_crit = '' warning = opts.warning or def_warn critical = opts.critical or def_crit if warning.endswith('%'): warning = warning[:-1] try: warning = float(warning) except ValueError: