Skip to content

Instantly share code, notes, and snippets.

@unicolet
Last active April 22, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unicolet/01127e9cb77b4792e0cb9057bf2af8ca to your computer and use it in GitHub Desktop.
Save unicolet/01127e9cb77b4792e0cb9057bf2af8ca to your computer and use it in GitHub Desktop.
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