Skip to content

Commit

Permalink
feat!: Move InfluxDB settings to their own section in config file
Browse files Browse the repository at this point in the history
Implements #670

feat: Add InfluxDB as destination for Windows service status monitoring
  • Loading branch information
Göran Sander committed May 28, 2023
1 parent 03dd309 commit d2e4d25
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
],
});
Expand Down
31 changes: 19 additions & 12 deletions src/lib/post_to_influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
},
},
];
Expand Down
6 changes: 3 additions & 3 deletions src/lib/service_monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit d2e4d25

Please sign in to comment.