Skip to content

Commit b686418

Browse files
authored
Merge pull request #71 from jschoewe/feature/add-monitoring-disable-plan-for-prometheus
feature/add-monitoring-disable-plan-for-prometheus
2 parents 5150f8e + 157b273 commit b686418

File tree

9 files changed

+507
-15
lines changed

9 files changed

+507
-15
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ All notable changes to this project will be documented in this file.
88

99
Contributed by Nick Maludy (@nmaludy)
1010

11+
## Release 1.2.0 (2020-12-02)
12+
13+
* Added monitoring_prometheus bolt plan and task to optionally create/delete silences
14+
in Prometheus to suppress alerts for the given targets.
15+
16+
* Added monitoring_multiple bolt plan to enable/disable monitoring for multiple
17+
different services at once.
18+
19+
Contributed by John Schoewe (@jschoewe)
20+
1121
## Release 1.1.1 (2020-06-09)
1222

1323
* Fixed header line for CSV

REFERENCE.md

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
* [`cache_update_linux`](#cache_update_linux): Updates the targets update cache. For RHEL/CentOS this means a `yum clean expire-cache`. For Debian this means a `apt update`.
3030
* [`cache_update_windows`](#cache_update_windows): Updates the targets update cache. For Windows this means a Windows Update refresh.
3131
* [`history`](#history): Reads the update history from the JSON 'result_file'.
32+
* [`monitoring_multiple`](#monitoring_multiple): Enable or disable monitoring alerts for multiple monitoring services at once.
33+
* [`monitoring_prometheus`](#monitoring_prometheus): Create or remove alert silences for hosts in Prometheus.
3234
* [`monitoring_solarwinds`](#monitoring_solarwinds): Enable or disable monitoring alerts on hosts in SolarWinds.
3335
* [`post_update`](#post_update): Run post-update script on target host(s), only if it exists. If the script doesn't exist or isn't executable, then this task succeeds (this a
3436
* [`pre_post_update_linux`](#pre_post_update_linux): Pre-post-update definition to make bolt not throw a warning. Best to use pre_update or post_update directly.
@@ -54,7 +56,9 @@
5456
* [`patching::deploy_scripts`](#patchingdeploy_scripts):
5557
* [`patching::get_facts`](#patchingget_facts): Sets patching facts on targets
5658
* [`patching::get_targets`](#patchingget_targets): <code>get_targets()</code> except it also performs online checks and gathers facts in one step.
57-
* [`patching::monitoring_solarwinds`](#patchingmonitoring_solarwinds): Creates or deletes VM snapshots on targets in VMware.
59+
* [`patching::monitoring_multiple`](#patchingmonitoring_multiple): Enable or disable monitoring alerts for multiple monitoring services at once.
60+
* [`patching::monitoring_prometheus`](#patchingmonitoring_prometheus): Create or remove alert silences for hosts in Prometheus.
61+
* [`patching::monitoring_solarwinds`](#patchingmonitoring_solarwinds): Enable or disable monitoring alerts on hosts in SolarWinds.
5862
* [`patching::ordered_groups`](#patchingordered_groups): Takes a set of targets then groups and sorts them by the <code>patching_order</code> var set on the target.
5963
* [`patching::post_update`](#patchingpost_update): Executes a custom post-update script on each node.
6064
* [`patching::pre_post_update`](#patchingpre_post_update): Common entry point for executing the pre/post update custom scripts
@@ -496,6 +500,44 @@ Data type: `Optional[String[1]]`
496500

497501
Log file for patching results. This file will contain the JSON output that is returned from these tasks. This is data that was written by patching::update. If no script name is passed on Linux hosts a default is used: /var/log/patching.json. If no script name is passed on Windows hosts a default is used: C:/ProgramData/PuppetLabs/patching/patching.json
498502

503+
### monitoring_prometheus
504+
505+
Create or remove alert silences for hosts in Prometheus.
506+
507+
**Supports noop?** true
508+
509+
#### Parameters
510+
511+
##### `targets`
512+
513+
Data type: `Variant[String[1], Array[String[1]]]`
514+
515+
List of hostnames or IP addresses for targets in SolarWinds that will have monitoring alerts either enabled or disabled.
516+
517+
##### `action`
518+
519+
Data type: `Enum['enable', 'disable']`
520+
521+
Action to perform on monitored targets. 'enable' will enable monitoring alerts. 'disable' will disable monitoring alerts on targets.
522+
523+
##### `prometheus_server`
524+
525+
Data type: `String[1]`
526+
527+
FQDN of the Prometheus server to create an alert silence for
528+
529+
##### `silence_duration`
530+
531+
Data type: `Optional[Integer]`
532+
533+
How long the alert silence will be alive for
534+
535+
##### `silence_units`
536+
537+
Data type: `Optional[Enum['minutes', 'hours', 'days', 'weeks']]`
538+
539+
Goes with the silence duration to determine how long the alert silence will be alive for
540+
499541
### monitoring_solarwinds
500542

501543
Enable or disable monitoring alerts on hosts in SolarWinds.
@@ -1290,6 +1332,156 @@ Data type: `TargetSpec`
12901332

12911333
Set of targets to run against.
12921334

1335+
### patching::monitoring_multiple
1336+
1337+
Disable monitoring for targets in multiple services
1338+
1339+
#### Examples
1340+
1341+
##### Remote target definition for $monitoring_target
1342+
1343+
```puppet
1344+
vars:
1345+
patching_monitoring_plan: 'patching::monitoring_multiple'
1346+
patching_monitoring_plan_multiple:
1347+
- plan: 'patching::monitoring_solarwinds'
1348+
target: 'solarwinds'
1349+
- plan: 'patching::monitoring_prometheus'
1350+
target: 'prometheus'
1351+
1352+
groups:
1353+
- name: solarwinds
1354+
config:
1355+
transport: remote
1356+
remote:
1357+
port: 17778
1358+
username: 'domain\svc_bolt_sw'
1359+
password:
1360+
_plugin: pkcs7
1361+
encrypted_value: >
1362+
ENC[PKCS7,xxx]
1363+
targets:
1364+
- solarwinds.domain.tld
1365+
1366+
- name: prometheus
1367+
config:
1368+
transport: remote
1369+
remote:
1370+
username: 'domain\prom_user'
1371+
password:
1372+
_plugin: pkcs7
1373+
encrypted_value: >
1374+
ENC[PKCS7,xxx]
1375+
targets:
1376+
- prometheus.domain.tld
1377+
```
1378+
1379+
#### Parameters
1380+
1381+
The following parameters are available in the `patching::monitoring_multiple` plan.
1382+
1383+
##### `targets`
1384+
1385+
Data type: `TargetSpec`
1386+
1387+
Set of targets to run against.
1388+
1389+
##### `action`
1390+
1391+
Data type: `Enum['enable', 'disable']`
1392+
1393+
What action to perform on the monitored targets:
1394+
1395+
- `enable` Resumes monitoring alerts
1396+
- 'disable' Supresses monitoring alerts
1397+
1398+
##### `monitoring_plan`
1399+
1400+
Data type: `Array`
1401+
1402+
List of monitoring plans to run if multiple monitoring services need to be enabled/disabled.
1403+
1404+
Default value: `.vars['patching_monitoring_target']`
1405+
1406+
##### `noop`
1407+
1408+
Data type: `Boolean`
1409+
1410+
Flag to enable noop mode. When noop mode is enabled no snapshots will be created or deleted.
1411+
1412+
Default value: `false`
1413+
1414+
### patching::monitoring_prometheus
1415+
1416+
Create or remove alert silences for hosts in Prometheus.
1417+
1418+
#### Examples
1419+
1420+
##### Remote target definition for $monitoring_target
1421+
1422+
```puppet
1423+
vars:
1424+
patching_monitoring_target: 'prometheus'
1425+
patching_monitoring_silence_duration: 24
1426+
patching_monitoring_silence_units: 'hours'
1427+
1428+
groups:
1429+
- name: prometheus
1430+
config:
1431+
transport: remote
1432+
remote:
1433+
username: 'domain\prom_user'
1434+
password:
1435+
_plugin: pkcs7
1436+
encrypted_value: >
1437+
ENC[PKCS7,xxx]
1438+
targets:
1439+
- prometheus.domain.tld
1440+
```
1441+
1442+
#### Parameters
1443+
1444+
The following parameters are available in the `patching::monitoring_prometheus` plan.
1445+
1446+
##### `targets`
1447+
1448+
Data type: `TargetSpec`
1449+
1450+
Set of targets to run against.
1451+
1452+
##### `action`
1453+
1454+
Data type: `Enum['enable', 'disable']`
1455+
1456+
What action to perform on the monitored targets:
1457+
1458+
- `enable` Resumes monitoring alerts
1459+
- 'disable' Supresses monitoring alerts
1460+
1461+
##### `monitoring_silence_duration`
1462+
1463+
Data type: `Optional[Integer]`
1464+
1465+
How long the alert silence will be alive for
1466+
1467+
Default Value: `.vars['patching_monitoring_silence_duration']`
1468+
1469+
##### `monitoring_silence_units`
1470+
1471+
Data type: `Optional[Enum['minutes', 'hours', 'days', 'weeks']]`
1472+
1473+
Goes with the silence duration to determine how long the alert silence will be alive for
1474+
1475+
Default Value: `.vars['patching_monitoring_silence_units']`
1476+
1477+
##### `noop`
1478+
1479+
Data type: `Boolean`
1480+
1481+
Flag to enable noop mode. When noop mode is enabled no snapshots will be created or deleted.
1482+
1483+
Default value: `false`
1484+
12931485
### patching::monitoring_solarwinds
12941486

12951487
Communicates to the vSphere API from the local Bolt control node using

lib/puppet_x/encore/patching/http_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@ def get(url, body: nil, headers: @headers)
7474
def post(url, body: nil, headers: @headers)
7575
execute('post', url, body: body, headers: headers, redirect_limit: @redirect_limit)
7676
end
77+
78+
def delete(url, body: nil, headers: @headers)
79+
execute('delete', url, body: body, headers: headers, redirect_limit: @redirect_limit)
80+
end
7781
end
7882
end

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "encore-patching",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"author": "Encore Technologies",
55
"summary": "Implements OS patching workflows using Bolt tasks and plans.",
66
"license": "Apache-2.0",

plans/monitoring_multiple.pp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# @summary Disable monitoring for targets in multiple services
2+
#
3+
# @param [TargetSpec] targets
4+
# Set of targets to run against.
5+
#
6+
# @param [Enum['enable', 'disable']] action
7+
# What action to perform on the monitored targets:
8+
#
9+
# - `enable` Resumes monitoring alerts
10+
# - 'disable' Supresses monitoring alerts
11+
#
12+
# @param [Boolean] noop
13+
# Flag to enable noop mode.
14+
#
15+
# @example Remote target definition for $monitoring_target
16+
# vars:
17+
# patching_monitoring_plan: 'patching::monitoring_multiple'
18+
# patching_monitoring_plan_multiple:
19+
# - plan: 'patching::monitoring_solarwinds'
20+
# target: 'solarwinds'
21+
# - plan: 'patching::monitoring_prometheus'
22+
# target: 'prometheus'
23+
#
24+
# groups:
25+
# - name: solarwinds
26+
# config:
27+
# transport: remote
28+
# remote:
29+
# port: 17778
30+
# username: 'domain\svc_bolt_sw'
31+
# password:
32+
# _plugin: pkcs7
33+
# encrypted_value: >
34+
# ENC[PKCS7,xxx]
35+
# targets:
36+
# - solarwinds.domain.tld
37+
#
38+
# - name: prometheus
39+
# config:
40+
# transport: remote
41+
# remote:
42+
# username: 'domain\prom_user'
43+
# password:
44+
# _plugin: pkcs7
45+
# encrypted_value: >
46+
# ENC[PKCS7,xxx]
47+
# targets:
48+
# - prometheus.domain.tld
49+
#
50+
plan patching::monitoring_multiple (
51+
TargetSpec $targets,
52+
Enum['enable', 'disable'] $action,
53+
Array[Hash] $monitoring_plans = get_targets($targets)[0].vars['patching_monitoring_plan_multiple'],
54+
Boolean $noop = false,
55+
) {
56+
57+
# Loop over and run each monitoring plan
58+
$monitoring_plans.each |Hash $plan_hash| {
59+
if $plan_hash['target'] {
60+
run_plan($plan_hash['plan'], $targets,
61+
action => $action,
62+
monitoring_target => $plan_hash['target'],
63+
noop => $noop)
64+
}
65+
else {
66+
run_plan($plan_hash['plan'], $targets,
67+
action => $action,
68+
noop => $noop)
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)