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()
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()