def to_json(self): ar = [] for a in self.attrs: r = [" {"] r += [' "name": "%s",' % q(a.name)] r += [' "type": "%s",' % q(a.type)] r += [' "description": "%s",' % q(a.description)] r += [' "required": %s,' % q(a.required)] r += [' "is_const": %s' % q(a.is_const)] r += [" }"] ar += ["\n".join(r)] r = [ "{", ' "name": "%s",' % q(self.name), ' "$collection": "%s",' % self._meta["json_collection"], ' "uuid": "%s",' % str(self.uuid), ' "description": "%s",' % q(self.description), ' "attrs": [', ",\n".join(ar), " ]", "}", ] return "\n".join(r) + "\n"
def to_json(self): c = self r = ["{"] r += [' "name": "%s",' % q(c.name)] r += [' "$collection": "%s",' % self._meta["json_collection"]] r += [' "uuid": "%s",' % c.uuid] if c.description: r += [' "description": "%s",' % q(c.description)] r += [' "action": "%s",' % q(c.action)] # vars vars = [] for v in c.vars: vd = [" {"] vd += [' "name": "%s",' % q(v.name)] vd += [' "description": "%s",' % q(v.description)] vd += [' "type": "%s",' % q(v.type)] vd += [' "required": %s' % q(v.required)] vd += [" }"] vars += ["\n".join(vd)] r += [' "vars": ['] r += [",\n".join(vars)] r += [" ],"] if self.link_event: r += [' "link_event": true,'] r += [' "deduplication_window": %d,' % self.deduplication_window] r += [' "ttl": %d,' % self.ttl] # Handlers if self.handlers: hh = [' "%s"' % h for h in self.handlers] r += [' "handlers": ['] r += [",\n\n".join(hh)] r += [" ],"] # Text r += [' "subject_template": "%s",' % q(c.subject_template)] r += [' "body_template": "%s",' % q(c.body_template)] r += [' "symptoms": "%s",' % q(c.symptoms)] r += [' "probable_causes": "%s",' % q(c.probable_causes)] r += [' "recommended_actions": "%s",' % q(c.recommended_actions)] # Disposition rules if c.disposition: r += [' "disposition": ['] disp = [] for d in c.disposition: ll = [" {"] lll = [' "name": "%s"' % q(d.name)] lll += [' "condition": "%s"' % q(d.condition)] lll += [' "action": "%s"' % q(d.action)] if d.alarm_class: lll += [ ' "alarm_class__name": "%s"' % q(d.alarm_class.name) ] if d.managed_object: lll += [ ' "managed_object": "%s"' % q(d.managed_object) ] ll += [",\n".join(lll)] ll += [" }"] disp += ["\n".join(ll)] r += [",\n".join(disp)] r += [" ]"] # if not r[-1].endswith(","): r[-1] += "," r += [' "repeat_suppression": ['] if c.repeat_suppression: rep = [] for rs in c.repeat_suppression: ll = [" {"] lll = [' "name": "%s",' % q(rs.name)] lll += [' "condition": "%s",' % q(rs.condition)] lll += [ ' "event_class__name": "%s",' % q(rs.event_class.name) ] lll += [' "match_condition": {'] llll = [] for rsc in rs.match_condition: llll += [ ' "%s": "%s"' % (q(rsc), q(rs.match_condition[rsc])) ] lll += [",\n".join(llll) + "\n },"] lll += [' "window": %d,' % rs.window] lll += [ ' "suppress": %s' % ("true" if rs.suppress else "false") ] ll += ["\n".join(lll)] ll += [" }"] rep += ["\n".join(ll)] r += [",\n".join(rep)] r += [" ]"] # Plugins if self.plugins: if not r[-1].endswith(","): r[-1] += "," plugins = [] for p in self.plugins: pd = [" {"] pd += [' "name": "%s"' % p.name] if p.config: pd[-1] += "," pc = [] for v in p.config: pc += [ ' "%s": "%s"' % (v, p.config.vars[v]) ] pd += [' "config": {'] pd += [",\n".join(pc)] pd += [" }"] pd += [" }"] plugins += ["\n".join(pd)] r += [' "plugins": ['] r += [",\n".join(plugins)] r += [" ]"] # Close if r[-1].endswith(","): r[-1] = r[-1][:-1] r += ["}", ""] return "\n".join(r)
def to_json(self): c = self r = ["{"] r += [' "name": "%s",' % q(c.name)] r += [' "$collection": "%s",' % self._meta["json_collection"]] r += [' "uuid": "%s",' % c.uuid] if c.description: r += [' "desciption": "%s",' % q(c.description)] r += [' "is_unique": %s,' % q(c.is_unique)] if c.is_unique and c.discriminator: r += [ ' "discriminator": [%s],' % ", ".join(['"%s"' % q(d) for d in c.discriminator]) ] r += [' "user_clearable": %s,' % q(c.user_clearable)] r += [ ' "default_severity__name": "%s",' % q(c.default_severity.name) ] # datasources if c.datasources: r += [' "datasources": ['] jds = [] for ds in c.datasources: x = [] x += [' "name": "%s"' % q(ds.name)] x += [' "datasource": "%s"' % q(ds.datasource)] ss = [] for k in sorted(ds.search): ss += [ ' "%s": "%s"' % (q(k), q(ds.search[k])) ] x += [ ' "search": {\n%s\n }' % (",\n".join(ss)) ] jds += [" {\n%s\n }" % ",\n".join(x)] r += [",\n\n".join(jds)] r += [" ],"] # vars vars = [] for v in c.vars: vd = [" {"] vd += [' "name": "%s",' % q(v.name)] vd += [' "description": "%s"' % q(v.description)] if v.default: vd[-1] += "," vd += [' "default": "%s"' % q(v.default)] vd += [" }"] vars += ["\n".join(vd)] r += [' "vars": ['] r += [",\n".join(vars)] r += [" ],"] # Handlers if self.handlers: hh = [' "%s"' % h for h in self.handlers] r += [' "handlers": ['] r += [",\n\n".join(hh)] r += [" ],"] if self.clear_handlers: hh = [' "%s"' % h for h in self.clear_handlers] r += [' "clear_handlers": ['] r += [",\n\n".join(hh)] r += [" ],"] # Text r += [' "subject_template": "%s",' % q(c.subject_template)] r += [' "body_template": "%s",' % q(c.body_template)] r += [' "symptoms": "%s",' % q(c.symptoms if c.symptoms else "")] r += [ ' "probable_causes": "%s",' % q(c.probable_causes if c.probable_causes else "") ] r += [ ' "recommended_actions": "%s",' % q(c.recommended_actions if c.recommended_actions else "") ] # Root cause if self.root_cause: rc = [] for rr in self.root_cause: rcd = [" {"] rcd += [' "name": "%s",' % rr.name] rcd += [' "root__name": "%s",' % rr.root.name] rcd += [' "window": %d,' % rr.window] if rr.condition: rcd += [' "condition": "%s",' % rr.condition] rcd += [' "match_condition": {'] mcv = [] for v in rr.match_condition: mcv += [ ' "%s": "%s"' % (v, rr.match_condition[v]) ] rcd += [",\n".join(mcv)] rcd += [" }"] rcd += [" }"] rc += ["\n".join(rcd)] if r[-1][-1] != ",": r[-1] += "," r += [' "root_cause": ['] r += [",\n".join(rc)] r += [" ]"] if self.topology_rca: if r[-1][-1] != ",": r[-1] += "," r += [' "topology_rca": true'] # Plugins if self.plugins: if r[-1][-1] != ",": r[-1] += "," plugins = [] for p in self.plugins: pd = [" {"] pd += [' "name": "%s"' % p.name] if p.config: pd[-1] += "," pc = [] for v in p.config: pc += [ ' "%s": "%s"' % (v, p.config.vars[v]) ] pd += [' "config": {'] pd += [",\n".join(pc)] pd += [" }"] pd += [" }"] plugins += ["\n".join(pd)] r += [' "plugins": ['] r += [",\n".join(plugins)] r += [" ]"] if self.notification_delay: if r[-1][-1] != ",": r[-1] += "," r += [' "notification_delay": %d' % self.notification_delay] if self.control_time0: if r[-1][-1] != ",": r[-1] += "," r += [' "control_time0": %d' % self.control_time0] if self.control_time1: r[-1] += "," r += [' "control_time1": %d' % self.control_time1] if self.control_timeN: r[-1] += "," r += [' "control_timeN": %d' % self.control_timeN] if self.recover_time: if r[-1][-1] != ",": r[-1] += "," r += [' "recover_time": %d' % self.recover_time] # Close if r[-1].endswith(","): r[-1] = r[-1][:-1] r += ["}", ""] return "\n".join(r)