From 87289dd6596a6fd017e48822cf890cc3e5c2fec5 Mon Sep 17 00:00:00 2001 From: matjaz99 Date: Sun, 1 Jan 2023 23:51:32 +0100 Subject: [PATCH] minor fixes --- providers.yml | 8 +++- .../model/config/ConfigReader.java | 3 +- .../prometheus/PrometheusHttpClient.java | 18 ++++----- .../alertmonitor/util/AmProps.java | 3 +- .../alertmonitor/util/OnStartListener.java | 2 +- src/main/webapp/providers/providers.xhtml | 37 +------------------ src/main/webapp/report/report.xhtml | 10 ++++- 7 files changed, 31 insertions(+), 50 deletions(-) diff --git a/providers.yml b/providers.yml index 327bac0..d6cfb83 100644 --- a/providers.yml +++ b/providers.yml @@ -35,6 +35,12 @@ providers: params: server: http://swarm1:7073/eventlogger syncInterval: 0 - - name: dummy + - name: no-params type: prometheus uri: /alertmonitor/webhook/dummy + - name: sync-off + type: prometheus + uri: /alertmonitor/webhook/test + params: + server: http://test:9090 + syncInterval: 0 diff --git a/src/main/java/si/matjazcerkvenik/alertmonitor/model/config/ConfigReader.java b/src/main/java/si/matjazcerkvenik/alertmonitor/model/config/ConfigReader.java index 8486ea7..65b1372 100644 --- a/src/main/java/si/matjazcerkvenik/alertmonitor/model/config/ConfigReader.java +++ b/src/main/java/si/matjazcerkvenik/alertmonitor/model/config/ConfigReader.java @@ -29,7 +29,7 @@ public class ConfigReader { - public static YamlConfig loadProvidersYaml(String path) { + public static YamlConfig loadProvidersYamlConfig(String path) { Representer representer = new Representer(); representer.getPropertyUtils().setSkipMissingProperties(true); Yaml yaml = new Yaml(new Constructor(YamlConfig.class), representer); @@ -87,7 +87,6 @@ public static List verifyConfigs(List configs) t } - return configs; } diff --git a/src/main/java/si/matjazcerkvenik/alertmonitor/model/prometheus/PrometheusHttpClient.java b/src/main/java/si/matjazcerkvenik/alertmonitor/model/prometheus/PrometheusHttpClient.java index aadb363..b1547bb 100644 --- a/src/main/java/si/matjazcerkvenik/alertmonitor/model/prometheus/PrometheusHttpClient.java +++ b/src/main/java/si/matjazcerkvenik/alertmonitor/model/prometheus/PrometheusHttpClient.java @@ -260,7 +260,7 @@ public List rules() throws PrometheusHttpClientException { */ private String execute(Request request) throws PrometheusHttpClientException { - requestCount++; + long reqID = requestCount++; String responseBody = null; long before = System.currentTimeMillis(); @@ -270,15 +270,15 @@ private String execute(Request request) throws PrometheusHttpClientException { OkHttpClient httpClient = HttpClientFactory.instantiateHttpClient(secureClient, connectTimeout, readTimeout, basicAuthUsername, basicAuthPassword); - logger.info("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] " + request.method().toUpperCase() + " " + request.url().toString()); + logger.info("PrometheusHttpClient[" + name + "]: request[" + reqID + "] " + request.method().toUpperCase() + " " + request.url().toString()); Response response = httpClient.newCall(request).execute(); - logger.info("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] code=" + response.code() + ", success=" + response.isSuccessful()); + logger.info("PrometheusHttpClient[" + name + "]: request[" + reqID + "] code=" + response.code() + ", success=" + response.isSuccessful()); code = Integer.toString(response.code()); if (response.body() != null) { responseBody = response.body().string(); - logger.debug("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] body: " + responseBody); + logger.debug("PrometheusHttpClient[" + name + "]: request[" + reqID + "] body: " + responseBody); } response.close(); @@ -286,27 +286,27 @@ private String execute(Request request) throws PrometheusHttpClientException { dataProvider.removeWarning("prom_api"); } catch (UnknownHostException e) { - logger.error("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] failed: UnknownHostException: " + e.getMessage()); + logger.error("PrometheusHttpClient[" + name + "]: request[" + reqID + "] failed: UnknownHostException: " + e.getMessage()); code = "0"; dataProvider.addWarning("prom_api", "Prometheus API not reachable", DWarning.DWARNING_SEVERITY_CRITICAL); throw new PrometheusHttpClientException("Unknown Host"); } catch (SocketTimeoutException e) { - logger.error("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] failed: SocketTimeoutException: " + e.getMessage()); + logger.error("PrometheusHttpClient[" + name + "]: request[" + reqID + "] failed: SocketTimeoutException: " + e.getMessage()); code = "0"; dataProvider.addWarning("prom_api", "Prometheus API not reachable", DWarning.DWARNING_SEVERITY_CRITICAL); throw new PrometheusHttpClientException("Timeout"); } catch (SocketException e) { - logger.error("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] failed: SocketException: " + e.getMessage()); + logger.error("PrometheusHttpClient[" + name + "]: request[" + reqID + "] failed: SocketException: " + e.getMessage()); code = "0"; dataProvider.addWarning("prom_api", "Prometheus API not reachable", DWarning.DWARNING_SEVERITY_CRITICAL); throw new PrometheusHttpClientException("Socket Error"); } catch (SSLException e) { - logger.error("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] failed: SSLException: " + e.getMessage()); + logger.error("PrometheusHttpClient[" + name + "]: request[" + reqID + "] failed: SSLException: " + e.getMessage()); code = "0"; dataProvider.addWarning("prom_api", "Prometheus API not reachable", DWarning.DWARNING_SEVERITY_CRITICAL); throw new PrometheusHttpClientException("SSL Exception"); } catch (Exception e) { - logger.error("PrometheusHttpClient[" + name + "]: request[" + requestCount + "] failed: Exception: ", e); + logger.error("PrometheusHttpClient[" + name + "]: request[" + reqID + "] failed: Exception: ", e); code = "0"; dataProvider.addWarning("prom_api", "Prometheus API not reachable", DWarning.DWARNING_SEVERITY_CRITICAL); throw new PrometheusHttpClientException("Unknown Exception"); diff --git a/src/main/java/si/matjazcerkvenik/alertmonitor/util/AmProps.java b/src/main/java/si/matjazcerkvenik/alertmonitor/util/AmProps.java index 8f0dd78..3b9b1cf 100644 --- a/src/main/java/si/matjazcerkvenik/alertmonitor/util/AmProps.java +++ b/src/main/java/si/matjazcerkvenik/alertmonitor/util/AmProps.java @@ -55,6 +55,7 @@ public class AmProps { public static void loadProps() { // read configuration from environment variables + // these are defaults if nothing is configured ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE = System.getenv().getOrDefault("ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE", "/opt/alertmonitor/providers.yml").trim(); ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME = System.getenv().getOrDefault("ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME", ".default").trim(); ALERTMONITOR_DATA_RETENTION_DAYS = Integer.parseInt(System.getenv().getOrDefault("ALERTMONITOR_DATA_RETENTION_DAYS", "30").trim()); @@ -83,7 +84,7 @@ public static void loadProps() { ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@elasticvm:27017/?authSource=admin"; ALERTMONITOR_MONGODB_DB_NAME = "alrtmonitor-dev"; ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE = "providers.yml"; - ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME = "MONIS"; + //ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME = "MONIS"; } } diff --git a/src/main/java/si/matjazcerkvenik/alertmonitor/util/OnStartListener.java b/src/main/java/si/matjazcerkvenik/alertmonitor/util/OnStartListener.java index f37b5ee..c86b447 100644 --- a/src/main/java/si/matjazcerkvenik/alertmonitor/util/OnStartListener.java +++ b/src/main/java/si/matjazcerkvenik/alertmonitor/util/OnStartListener.java @@ -89,7 +89,7 @@ public void contextInitialized(ServletContextEvent servletContextEvent) { } // load yaml config file - AmProps.yamlConfig = ConfigReader.loadProvidersYaml(AmProps.ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE); + AmProps.yamlConfig = ConfigReader.loadProvidersYamlConfig(AmProps.ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE); // initialize DAO DAO.getInstance(); diff --git a/src/main/webapp/providers/providers.xhtml b/src/main/webapp/providers/providers.xhtml index d39b40d..43b3e18 100644 --- a/src/main/webapp/providers/providers.xhtml +++ b/src/main/webapp/providers/providers.xhtml @@ -46,42 +46,9 @@ +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/main/webapp/report/report.xhtml b/src/main/webapp/report/report.xhtml index d4c0583..23f7b78 100644 --- a/src/main/webapp/report/report.xhtml +++ b/src/main/webapp/report/report.xhtml @@ -19,13 +19,21 @@ In last hour there were uiReportBean.adp.numberOfAlertsInLastHour events. Currently, there are #{uiReportBean.adp.allActiveAlarmsCount} active alerts on #{uiReportBean.adp.activeTargets.size()} targets.

+



-
+ +

+ + +

Periodic synchronization interval is set to #{uiReportBean.adp.syncInterval} seconds. Since start there were #{uiReportBean.adp.syncSuccessCount} successful syncs and #{uiReportBean.adp.syncFailedCount} failed.

+

+ This provider listens for incoming requests on #{uiReportBean.adp.providerConfig.uri} webhook. So far a total of #{uiReportBean.adp.webhookRequestsReceivedCount} requests were received which contain #{uiReportBean.adp.journalCount} events. Current journal size is: #{uiReportBean.adp.journalSize}. +