Esempio n. 1
0
 def import_triggers(self):
     ''' Create/update zabbix IDn for all matched CI's '''
     triggers = zabbix.get_all_triggers()
     for h in triggers:
         existing = db.CIChangeZabbixTrigger.objects.filter(
             trigger_id=h.get('triggerid')).all()
         if not existing:
             logger.debug('Integrate %s' % h.get('triggerid'))
             c = db.CIChange()
             c.type = db.CI_CHANGE_TYPES.ZABBIX_TRIGGER.id
             c.priority = db.CI_CHANGE_PRIORITY_TYPES.ERROR.id
             #create zabbix type change as container
             ch = db.CIChangeZabbixTrigger()
         else:
             ch = existing[0]
             c = db.CIChange.objects.get(
                 type=db.CI_CHANGE_TYPES.ZABBIX_TRIGGER.id, object_id=ch.id)
         ch.ci = self.get_ci_by_name(h.get('host'))
         ch.trigger_id = h.get('triggerid')
         ch.host = h.get('host')
         ch.host_id = h.get('hostid')
         ch.status = h.get('status')
         ch.priority = h.get('priority')
         ch.description = h.get('description')
         ch.lastchange = datetime.datetime.fromtimestamp(
             float(h.get('lastchange')))
         ch.comments = h.get('comments')
         ch.save()
         c.content_object = ch
         c.ci = ch.ci
         c.time = datetime.datetime.fromtimestamp(float(
             h.get('lastchange')))
         c.message = ch.description
         c.save()
Esempio n. 2
0
 def import_changes(self):
     device_type = ContentType.objects.get(app_label="discovery",
                                           model="device")
     for x in HistoryChange.objects.filter(user_id__gt=0, device__gt=0):
         try:
             ch = db.CIChange()
             ch.content_object = x
             ci = None
             ci = db.CI.objects.filter(object_id=x.device.id,
                                       content_type=device_type).all()[0]
             ch.ci = ci
             ch.priority = db.CI_CHANGE_PRIORITY_TYPES.WARNING.id
             ch.time = x.date
             ch.message = x.comment or ''
             ch.type = db.CI_CHANGE_TYPES.DEVICE.id
             ch.save()
         except IntegrityError, e:
             logger.debug('Skipping already imported: %s' % x)
Esempio n. 3
0
 def import_changes(self):
     device_type = ContentType.objects.get(
         app_label="discovery", model="device")
     for x in HistoryChange.objects.filter(user_id__gt=0, device__gt=0):
         try:
             ch = db.CIChange()
             ch.content_object = x
             try:
                 ci = db.CI.objects.get(
                     object_id=x.device.id, content_type=device_type)
             except db.CI.DoesNotExist:
                 continue
             ch.ci = ci
             ch.priority = db.CI_CHANGE_PRIORITY_TYPES.WARNING.id
             ch.time = x.date
             ch.message = x.comment or ''
             ch.type = db.CI_CHANGE_TYPES.DEVICE.id
             if x.user_id:
                 ch.registration_type = chdb.CI_CHANGE_REGISTRATION_TYPES.WAITING.id
             ch.save()
             register_issue_signal.send(sender=self, change_id=ch.id)
         except IntegrityError:
             logger.debug('Skipping already imported: %s' % x)