Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/161478

Change subject: nagios_common: Refactor custom command definitions
......................................................................

nagios_common: Refactor custom command definitions

- Setup a check_command define
- Separate commands config into one file per set of commands
- Move command config into a folder /etc/icinga/commands
- Move check_graphite to use the new system

Change-Id: I3c3bc48bf8730cd262ec32785ee6a7360f7e24aa
---
M files/icinga/icinga.cfg
M manifests/misc/icinga.pp
R modules/nagios_common/files/check_commands/check_graphite
A modules/nagios_common/files/check_commands/check_graphite.cfg
A modules/nagios_common/manifests/check_command.pp
5 files changed, 81 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/78/161478/1

diff --git a/files/icinga/icinga.cfg b/files/icinga/icinga.cfg
index f2fba6a..9991ee2 100644
--- a/files/icinga/icinga.cfg
+++ b/files/icinga/icinga.cfg
@@ -16,6 +16,7 @@
 
 # Commands definitions
 cfg_file=/etc/icinga/checkcommands.cfg
+cfg_dir=/etc/icinga/commands
 # Misc commands (notification and event handler commands, etc)
 cfg_file=/etc/icinga/misccommands.cfg
 
diff --git a/manifests/misc/icinga.pp b/manifests/misc/icinga.pp
index b374ada..948b3a0 100644
--- a/manifests/misc/icinga.pp
+++ b/manifests/misc/icinga.pp
@@ -185,6 +185,13 @@
         ensure  => 'absent',
     }
 
+    file { '/etc/icinga/commands.cfg':
+        ensure => directory,
+        owner  => 'root',
+        group  => 'root',
+        mode   => '0755',
+    }
+
     file { '/etc/icinga/checkcommands.cfg':
         content => template('icinga/checkcommands.cfg.erb'),
         owner   => 'root',
@@ -616,12 +623,11 @@
         group  => 'root',
         mode   => '0755',
     }
-    file { '/usr/lib/nagios/plugins/check_graphite':
-        source => 'puppet:///files/icinga/check_graphite',
-        owner  => 'root',
-        group  => 'root',
-        mode   => '0755',
+
+    nagios_common::check_command { 'check_graphite':
+        require => File['/etc/icinga/commands'],
     }
+
     # Include check_elasticsearch from elasticsearch module
     include elasticsearch::nagios::plugin
 
diff --git a/files/icinga/check_graphite 
b/modules/nagios_common/files/check_commands/check_graphite
similarity index 100%
rename from files/icinga/check_graphite
rename to modules/nagios_common/files/check_commands/check_graphite
diff --git a/modules/nagios_common/files/check_commands/check_graphite.cfg 
b/modules/nagios_common/files/check_commands/check_graphite.cfg
new file mode 100644
index 0000000..b8baf3a
--- /dev/null
+++ b/modules/nagios_common/files/check_commands/check_graphite.cfg
@@ -0,0 +1,16 @@
+# This file is managed by puppet
+# Generic checks for graphite
+define command{
+    command_name    check_graphite_threshold
+    command_line    $USER1$/check_graphite -U $ARG1$ -T $ARG2$ check_threshold 
'$ARG3$' -W $ARG4$ -C $ARG5$ --from $ARG6$ --perc $ARG7$ $ARG8$
+}
+
+define command{
+    command_name    check_graphite_series_threshold
+    command_line    $USER1$/check_graphite -U $ARG1$ -T $ARG2$ 
check_series_threshold '$ARG3$' -W $ARG4$ -C $ARG5$ --from $ARG6$ --perc $ARG7$ 
$ARG8$
+}
+
+define command{
+    command_name    check_graphite_anomaly
+    command_line    $USER1$/check_graphite -U $ARG1$ -T $ARG2$ check_anomaly 
'$ARG3$' -W $ARG4$ -C $ARG5$ --check_window $ARG6$ $ARG7$
+}
diff --git a/modules/nagios_common/manifests/check_command.pp 
b/modules/nagios_common/manifests/check_command.pp
new file mode 100644
index 0000000..337bfe0
--- /dev/null
+++ b/modules/nagios_common/manifests/check_command.pp
@@ -0,0 +1,53 @@
+# = Define: nagios_common::check_command
+# Defines a custom check command and configuration for that
+# command
+
+# [*ensure*]
+#   present or absent, to make the definition
+#   present or absent. Defaults to present
+#
+# [*config_dir*]
+#   The base directory to put configuration in.
+#   Defaults to '/etc/icinga/'
+#
+# [*owner*]
+#   The user which should own the config file.
+#   Defaults to 'root'
+#
+# [*group*]
+#   The group which should own the config file.
+#   Defaults to 'root'
+#
+define nagios_common::check_command(
+    $ensure = present,
+    $config_dir = '/etc/icinga',
+    $owner = 'root',
+    $group = 'root',
+    $config_content = undef,
+    $config_source = undef,
+) {
+    # The puppet path of the check command
+    $command_puppet_path = 
"puppet:///modules/nagios_common/check_commands/$title"
+
+    if $content == undef {
+        if $source == undef {
+            $source = 
"puppet:///modules/nagios_common/check_commands/$title.cfg"
+        }
+        $content = file($source)
+    }
+
+    file { "/usr/lib/nagios/plugins/$title":
+        ensure  => $ensure,
+        content => $command_puppet_path,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0755',
+    }
+
+    file { "$conf_dir/commands/$title.cfg":
+        ensure  => $ensure,
+        content => $content,
+        owner   => $owner,
+        group   => $group,
+    }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/161478
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c3bc48bf8730cd262ec32785ee6a7360f7e24aa
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to