From d2e4d256bf7ca1148495832ede95fae06068b0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Sun, 28 May 2023 16:44:43 +0200 Subject: [PATCH] feat!: Move InfluxDB settings to their own section in config file Implements #670 feat: Add InfluxDB as destination for Windows service status monitoring --- src/globals.js | 8 +++++--- src/lib/post_to_influxdb.js | 31 +++++++++++++++++++------------ src/lib/service_monitor.js | 6 +++--- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/globals.js b/src/globals.js index 3c937071..a1f7f07c 100644 --- a/src/globals.js +++ b/src/globals.js @@ -389,10 +389,12 @@ const influx = new Influx.InfluxDB({ { measurement: 'win_service_state', fields: { - state: Influx.FieldType.INTEGER, - startup_mode: Influx.FieldType.INTEGER, + state_num: Influx.FieldType.INTEGER, + state_text: Influx.FieldType.STRING, + startup_mode_num: Influx.FieldType.INTEGER, + startup_mode_text: Influx.FieldType.STRING, }, - tags: ['butler_instance', 'host', 'service_name', 'service_display_name'], + tags: ['butler_instance', 'host', 'service_name', 'display_name'], }, ], }); diff --git a/src/lib/post_to_influxdb.js b/src/lib/post_to_influxdb.js index e830a4d2..bc60331a 100755 --- a/src/lib/post_to_influxdb.js +++ b/src/lib/post_to_influxdb.js @@ -37,20 +37,21 @@ function postButlerMemoryUsageToInfluxdb(memory) { function postWindowsServiceStatusToInfluxDB(serviceStatus) { // Create lookup table for Windows service state to numeric value, starting with 1 for stopped const serviceStateLookup = { - stopped: 1, - start_pending: 2, - stop_pending: 3, - running: 4, - continue_pending: 5, - pause_pending: 6, - paused: 7, + STOPPED: 1, + START_PENDING: 2, + STOP_PENDING: 3, + RUNNING: 4, + CONTINUE_PENDING: 5, + PAUSE_PENDING: 6, + PAUSED: 7, }; // Create lookup table for Windows service startup mode to numeric value, starting with 0 const serviceStartupModeLookup = { - automatic: 0, - manual: 1, - disabled: 2, + Automatic: 0, + 'Automatic (delayed start)': 1, + Manual: 2, + Disabled: 3, }; let datapoint = [ @@ -63,8 +64,14 @@ function postWindowsServiceStatusToInfluxDB(serviceStatus) { display_name: serviceStatus.serviceDetails.displayName, }, fields: { - state: serviceStateLookup[serviceStatus.serviceStatus], - startup_mode: serviceStartupModeLookup[serviceStatus.serviceDetails.startupMode], + state_num: + serviceStateLookup[serviceStatus.serviceStatus] !== undefined ? serviceStateLookup[serviceStatus.serviceStatus] : -1, + state_text: serviceStatus.serviceStatus, + startup_mode_num: + serviceStartupModeLookup[serviceStatus.serviceDetails.startType] !== undefined + ? serviceStartupModeLookup[serviceStatus.serviceDetails.startType] + : -1, + startup_mode_text: serviceStatus.serviceDetails.startType, }, }, ]; diff --git a/src/lib/service_monitor.js b/src/lib/service_monitor.js index b0cbb2e9..d3698244 100644 --- a/src/lib/service_monitor.js +++ b/src/lib/service_monitor.js @@ -425,10 +425,10 @@ const checkServiceStatus = async (config, logger) => { globals.config.has('Butler.emailNotification.enable') && globals.config.has('Butler.serviceMonitor.alertDestination.influxDb.enable') && globals.config.get('Butler.emailNotification.enable') === true && - globals.config.get('Butler.serviceMonitor.alertDestination.InfluxDb.enable') === true + globals.config.get('Butler.serviceMonitor.alertDestination.influxDb.enable') === true ) { - const instanceTag = globals.config.has('Butler.influxDbConfig.instanceTag') - ? globals.config.get('Butler.influxDbConfig.instanceTag') + const instanceTag = globals.config.has('Butler.influxDb.instanceTag') + ? globals.config.get('Butler.influxDb.instanceTag') : ''; influxDb.postWindowsServiceStatusToInfluxDB({