Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Two postgres functions to retrieve param values from OpenNMS events.eventparms column. Tested on postgres 9.4
CREATE OR REPLACE FUNCTION event_pval_num(p_eventparams text, p_param text) RETURNS integer AS $$
BEGIN
RETURN (regexp_matches(p_eventparams,p_param||'=(\d+)'))[1];
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION event_pval_txt(p_eventparams text, p_param text) RETURNS text AS $$
BEGIN
RETURN (regexp_matches(p_eventparams,p_param||'=(.*?)\(string'))[1];
END;
$$ LANGUAGE plpgsql;
-- example:
-- select event_pval_txt(eventparms,'nodelabel') from events where eventuei='uei.opennms.org/nodes/nodeUp';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.