Last active
April 22, 2016 08:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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