Skip to content

Instantly share code, notes, and snippets.

@indigo423
Last active May 7, 2018 07:44
Show Gist options
  • Save indigo423/306758499244dbda0792998c339d0c38 to your computer and use it in GitHub Desktop.
Save indigo423/306758499244dbda0792998c339d0c38 to your computer and use it in GitHub Desktop.
OpenNMS View for nodes with outages and categories
CREATE VIEW node_outages AS (
SELECT
outages.outageid,
outages.svclosteventid,
outages.svcregainedeventid,
outages.iflostservice,
outages.ifregainedservice,
outages.ifserviceid,
e.eventuei AS svclosteventuei,
e.eventsource,
e.alarmid,
e.eventseverity,
(ifregainedservice NOTNULL) AS resolved,
s.servicename,
i.serviceid,
ipif.ipaddr,
COALESCE(outages.ifregainedservice - outages.iflostservice, now() - outages.iflostservice) AS duration,
nos.max_outage_severity,
nc.*
FROM
outages
JOIN
events e
ON
outages.svclosteventid = e.eventid
JOIN
ifservices i
ON
outages.ifserviceid = i.id
JOIN
service s
ON
i.serviceid = s.serviceid
JOIN
ipinterface ipif
ON
i.ipinterfaceid = ipif.id
JOIN
node_categories nc
ON
nc.nodeid = e.nodeid
JOIN
node_outage_status nos
ON
nc.nodeid = nos.nodeid
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment