Example #1
0
 def run(self):
     parser = PerfdataParser()
     last_flush = time.time()
     updates = []
     while True:
         lines = 0
         files = glob.glob(self.perfpattern)[:self.limit]
         if files:
             input = fileinput.input(files)
             for line in input:
                 try:
                     observation, perfdata = parser.parse(line)
                 except InvalidPerfdata, e:
                     sys.stderr.write(
                         "%s %s:%i\n  line: %s" %
                         (e, input.filename(), input.filelineno(), line))
                     continue
                 except Exception, e:
                     sys.stderr.write(
                         "Error while parsing perfdata: %s %s:%i\n  line: %s"
                         % (e, input.filename(), input.filelineno(), line))
                     continue
                 for performance_data in perfdata:
                     parentservice = None
                     service = observation['service']
                     if performance_data['child_service']:
                         parentservice = service
                         service = performance_data['child_service']
                     pluginstatus = observation['state']
                     if pluginstatus == 1:
                         pluginstatus = 'warning'
                     if pluginstatus == 2:
                         pluginstatus = 'critical'
                     updates.append(
                         (observation['host'], parentservice, service,
                          performance_data['label'],
                          observation['timestamp'], performance_data['uom'],
                          performance_data['value'],
                          performance_data['lower_limit'],
                          performance_data['upper_limit'],
                          performance_data['warn_lower'],
                          performance_data['warn_upper'],
                          performance_data['warn_type'],
                          performance_data['crit_lower'],
                          performance_data['crit_upper'],
                          performance_data['crit_type'], pluginstatus))
                 lines += 1
Example #2
0
 def run(self):
     parser = PerfdataParser()
     last_flush = time.time()
     updates = []
     while True:
         lines = 0
         files = glob.glob(self.perfpattern)[:self.limit]
         if files:
             input = fileinput.input(files)
             for line in input:
                 try:
                     observation, perfdata = parser.parse(line)
                 except InvalidPerfdata, e:
                     sys.stderr.write("%s %s:%i\n  line: %s" % (e, input.filename(), input.filelineno(), line))
                     continue
                 except Exception, e:
                     sys.stderr.write("Error while parsing perfdata: %s %s:%i\n  line: %s" % (e, input.filename(), input.filelineno(), line))
                     continue
                 for performance_data in perfdata:
                     parentservice = None
                     service = observation['service']
                     if performance_data['child_service']:
                         parentservice = service
                         service = performance_data['child_service']
                     pluginstatus = observation['state']
                     if pluginstatus == 1:
                         pluginstatus = 'warning'
                     if pluginstatus == 2:
                         pluginstatus = 'critical'
                     updates.append(
                         (observation['host'], parentservice, service,
                          performance_data['label'], observation['timestamp'], performance_data['uom'],
                          performance_data['value'], performance_data['lower_limit'],
                          performance_data['upper_limit'], performance_data['warn_lower'],
                          performance_data['warn_upper'], performance_data['warn_type'],
                          performance_data['crit_lower'], performance_data['crit_upper'],
                          performance_data['crit_type'], pluginstatus)
                     )
                 lines += 1
Example #3
0
    def run(self):
        parser = PerfdataParser()
        last_flush = time.time()
        updates = []
        while True:
            lines = 0
            files = glob.glob(self.perfpattern)[:self.limit]
            if files:
                input = fileinput.input(files)
                for line in input:
                    try:
                        observation, perfdata = parser.parse(line)
                    except InvalidPerfdata, e:
                        sys.stderr.write("%s %s:%i" % (e, input.filename(), input.filelineno()))
                        continue
                    for performance_data in perfdata:
                        parentservice = None
                        service = observation['service']
                        if performance_data['child_service']:
                            parentservice = service
                            service = performance_data['child_service']
                        pluginstatus = observation['state']
                        if pluginstatus == 1:
                            pluginstatus = 'warning'
                        if pluginstatus == 2:
                            pluginstatus = 'critical'
                        updates.append(
                            (observation['host'], parentservice, service,
                             performance_data['label'], observation['timestamp'], performance_data['uom'],
                             performance_data['value'], performance_data['lower_limit'],
                             performance_data['upper_limit'], performance_data['warn_lower'],
                             performance_data['warn_upper'], performance_data['warn_type'],
                             performance_data['crit_lower'], performance_data['crit_upper'],
                             performance_data['crit_type'], pluginstatus)
                        )
                    lines += 1

            if last_flush + 30 < time.time() or len(updates) >= 25000:
                if updates:
                    updates_pickled = pickle.dumps(updates)
                    st = time.time()
                    while True:
                        try:
                            self.api.insertValueBulk(updates_pickled)
                        except Exception:
                            time.sleep(60)
                        else:
                            break
                    et = time.time()
                    print "%d updates (approx. %d lines) took %f seconds" % \
                          (len(updates), lines, et - st)
                updates = []
                last_flush = time.time()
                lines = 0

            if files:
                if self.mode == 'BACKUP':
                    for file in files:
                        shutil.move(file, file + '.bak')
                elif self.mode == 'REMOVE':
                    for file in files:
                        os.remove(file)
            time.sleep(self.sleeptime)