Search in sources :

Example 1 with MatchTable

use of org.opennms.core.utils.MatchTable in project opennms by OpenNMS.

the class HttpNotificationStrategy method doSql.

private void doSql(String contents) {
    if (getSql() == null) {
        LOG.info("send: optional sql argument is null.");
        return;
    }
    if (contents == null) {
        LOG.info("doSql: HTTP reply is null");
        return;
    }
    LOG.debug("send: compiling expression: {}", getSwitchValue("result-match"));
    Pattern p = Pattern.compile(getSwitchValue("result-match"));
    Matcher m = p.matcher(contents);
    if (m.matches()) {
        LOG.debug("send: compiled expression ready to run sql: {}", getSql());
        MatchTable matches = new MatchTable(m);
        String sqlString = PropertiesUtils.substitute(getSql(), matches);
        LOG.debug("send: running sql: {}", sqlString);
        JdbcTemplate template = new JdbcTemplate(DataSourceFactory.getInstance());
        template.execute(sqlString);
    } else {
        LOG.info("send: result didn't match, not running sql");
    }
}
Also used : Pattern(java.util.regex.Pattern) MatchTable(org.opennms.core.utils.MatchTable) Matcher(java.util.regex.Matcher) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Aggregations

Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MatchTable (org.opennms.core.utils.MatchTable)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1