Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matjaz99 committed Jan 1, 2023
1 parent 10d1dd4 commit 87289dd
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 50 deletions.
8 changes: 7 additions & 1 deletion providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -87,7 +87,6 @@ public static List<ProviderConfig> verifyConfigs(List<ProviderConfig> configs) t

}


return configs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public List<PRule> rules() throws PrometheusHttpClientException {
*/
private String execute(Request request) throws PrometheusHttpClientException {

requestCount++;
long reqID = requestCount++;

String responseBody = null;
long before = System.currentTimeMillis();
Expand All @@ -270,43 +270,43 @@ 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();

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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";
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
37 changes: 2 additions & 35 deletions src/main/webapp/providers/providers.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,9 @@

</p:panelGrid>

<br/>

<p:panelGrid columns="5" cellpadding="0" cellspacing="15" width="100%" style="border: none">

<p:panelGrid columns="1" cellspacing="5" width="100%">
<p:outputLabel value="Active alerts" class="boldtext"/>
<p:outputLabel value="Critical: #{p.getActiveAlarmsCount('critical')}" />
<p:outputLabel value="Major: #{p.getActiveAlarmsCount('major')}" />
<p:outputLabel value="Minor: #{p.getActiveAlarmsCount('minor')}" />
<p:outputLabel value="Warning: #{p.getActiveAlarmsCount('warning')}" />
<p:outputLabel value="Total alerts: #{p.allActiveAlarmsCount}" />
<p:outputLabel value="Balance factor: #{p.balanceFactor}" />
</p:panelGrid>

<p:panelGrid columns="1" cellspacing="5" width="100%">
<p:outputLabel value="Counters" class="boldtext"/>
<p:outputLabel value="URI requests: #{p.webhookRequestsReceivedCount}" />
<p:outputLabel value="Journal events: #{p.journalCount}" />
<p:outputLabel value="Journal size: #{p.journalSize}" />
<p:outputLabel value="Firing count: #{p.raisingEventCount}" />
<p:outputLabel value="Resolved count: #{p.clearingEventCount}" />
<p:outputLabel value="-" />
</p:panelGrid>

<p:panelGrid columns="1" cellspacing="5" width="100%">
<p:outputLabel value="Sync" class="boldtext"/>
<p:outputLabel value="Sync interval: #{p.syncInterval} sec" />
<p:outputLabel value="-" />
<p:outputLabel value="Sync success: #{p.syncSuccessCount}" />
<p:outputLabel value="Sync fail: #{p.syncFailedCount}" />
<p:outputLabel value="-" />
<p:outputLabel value="-" />
</p:panelGrid>

</p:panelGrid>


<p:outputLabel value="Configuration parameters" class="boldtext"/>
<p:dataTable value="#{p.providerConfig.params}" var="c"
cellpadding="0" cellspacing="0">
<p:column headerText="Params">
Expand Down
10 changes: 9 additions & 1 deletion src/main/webapp/report/report.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</p>
<p:outputLabel value="Active alarms:" class="boldtext"/><br/>
<p:outputLabel value="Critical: #{uiReportBean.adp.getActiveAlarmsCount('critical')}" /><br/>
<p:outputLabel value="Major: #{uiReportBean.adp.getActiveAlarmsCount('major')}" /><br/>
<p:outputLabel value="Minor: #{uiReportBean.adp.getActiveAlarmsCount('minor')}" /><br/>
<p:outputLabel value="Warning: #{uiReportBean.adp.getActiveAlarmsCount('warning')}" /><br/>
<p:outputLabel value="Warning: #{uiReportBean.adp.getActiveAlarmsCount('warning')}" />
<p class="m-0">
<p:outputLabel value="Alarms balance factor: "/>
<p:outputLabel value="#{uiReportBean.adp.balanceFactor}" />
</p>
<p class="m-0">
Periodic synchronization interval is set to #{uiReportBean.adp.syncInterval} seconds. Since start there were #{uiReportBean.adp.syncSuccessCount} successful syncs and #{uiReportBean.adp.syncFailedCount} failed.
</p>
<p class="m-0">
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}.
</p>
</p:panel>

<p:panel header="Prometheus targets" styleClass="bottom-margin">
Expand Down

0 comments on commit 87289dd

Please sign in to comment.