refactor register class and client template
authorJerome Charaoui <jcharaoui@cmaisonneuve.qc.ca>
Fri, 14 May 2010 15:02:03 +0000 (11:02 -0400)
committerJerome Charaoui <jcharaoui@cmaisonneuve.qc.ca>
Fri, 14 May 2010 22:11:55 +0000 (18:11 -0400)
manifests/client/base.pp
manifests/register.pp
manifests/register/snmp.pp [new file with mode: 0644]
manifests/register_snmp.pp [deleted file]
templates/client.erb [new file with mode: 0644]
templates/defaultclient.erb [deleted file]
templates/snmpclient.erb [deleted file]

index afa12a0..17387e8 100644 (file)
@@ -18,6 +18,8 @@ class munin::client::base {
         notify => Service['munin-node'],
         mode => 0644, owner => root, group => 0,
     }
-    munin::register { $fqdn: }
+    munin::register { $fqdn:
+        config => [ 'use_node_name yes', 'load.load.warning 5', 'load.load.critical 10'],
+    }
     include munin::plugins::base
 }
index 05d8f2a..21f1d35 100644 (file)
@@ -1,30 +1,34 @@
-define munin::register(
+define munin::register (
   $host = 'absent',
-  $port = 'absent'
+  $port = 'absent',
+  $description = 'absent',
+  $config = []
 )
 {
+    $fhost = $name
+    $client_type = 'client'
+
     $munin_port_real = $port ? {
-    'absent' => $munin_port ? {
-                  '' => 4949,
-                  default => $munin_port
-                },
-    default => $port
-  }
+        'absent' => $munin_port ? {
+                        '' => 4949,
+                        default => $munin_port
+                    },
+        default => $port
+    }
 
     $munin_host_real = $host ? {
-    'absent' => $munin_host ? {
-                  '' => $fqdn,
-                  'fqdn' => $fqdn,
-                  default => $munin_host
-                },
-    default => $host
+        'absent' => $munin_host ? {
+                        '' => $fqdn,
+                        'fqdn' => $fqdn,
+                        default => $munin_host
+                    },
+        default => $host
     }
 
-    @@file { "/var/lib/puppet/modules/munin/nodes/${name}_${munin_port_real}":
+    @@file { "munin_client_${fhost}_${munin_port_real}":
         ensure => present,
-        content => template("munin/defaultclient.erb"),
+        path => "/var/lib/puppet/modules/munin/nodes/${fhost}_${munin_port_real}",
+        content => template("munin/client.erb"),
         tag => 'munin',
     }
 }
-
-
diff --git a/manifests/register/snmp.pp b/manifests/register/snmp.pp
new file mode 100644 (file)
index 0000000..c0d9279
--- /dev/null
@@ -0,0 +1,22 @@
+define munin::register::snmp (
+  $community = 'public',
+  $description = 'absent'
+)
+{
+    $fhost = $name
+    $munin_host_real = $fqdn
+    $client_type = 'snmp'
+    $config = [ 'use_node_name no' ]
+
+    exec { "munin_register_snmp_${fhost}":
+        command => "munin-node-configure --snmp ${fhost} --snmpcommunity ${community} | sh",
+        unless => "ls /etc/munin/plugins/snmp_${fhost}_* &> /dev/null",
+    }
+
+    @@file { "munin_snmp_${fhost}":
+        ensure => present,
+        path => "/var/lib/puppet/modules/munin/nodes/${fhost}",
+        content => template("munin/client.erb"),
+        tag => 'munin',
+    }
+}
diff --git a/manifests/register_snmp.pp b/manifests/register_snmp.pp
deleted file mode 100644 (file)
index ebd494a..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-# snmp_testplugin: the plugin we use to test if it's set
-define munin::register_snmp(
-    $snmpd_testplugin = 'load'
-)
-{
-    $munin_port_real = $munin_port ? { '' => 4949, default => $munin_port }
-    $munin_host_real = $munin_host ? {
-        '' => '*',
-        'fqdn' => '*',
-        default => $munin_host
-    }
-    exec{"register_snmp_munin_for_${name}":
-        command => "munin-node-configure-snmp ${name} | sh",
-        unless => "test -e /etc/munin/plugins/snmp_${name}_${snmpd_testplugin}",
-    }
-    @@file { "munin_snmp_${name}": path => "/var/lib/puppet/modules/munin/nodes/${name}",
-        ensure => present,
-        content => template("munin/snmpclient.erb"),
-        tag => 'munin',
-    }
-}
diff --git a/templates/client.erb b/templates/client.erb
new file mode 100644 (file)
index 0000000..e7c6730
--- /dev/null
@@ -0,0 +1,18 @@
+<%
+       # Downcase all information
+       dom = domain.downcase
+       host = hostname.downcase
+%>
+
+### Munin client from Puppet template
+# Domain: <%= dom %>
+# Registered on: <%= host %>
+# Type: <%= client_type %>
+<% if description != 'absent' -%>
+# Description: <%= description.gsub!(/\n/, ' ') %>
+<% end -%>
+[<%= fhost.downcase %>]
+    address <%= munin_host_real -%>
+<% if config -%><% config.each do |val| -%> 
+    <%= val -%>
+<% end -%><% end -%>
diff --git a/templates/defaultclient.erb b/templates/defaultclient.erb
deleted file mode 100644 (file)
index 5611bf4..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<%
-       # Downcase all information
-       dom = domain.downcase
-       host = hostname.downcase
-       fhost = name.downcase
-%>
-### This syntax can be extended, it might get better ...
-#+<%= dom %>
-#-<%= host %>=<%= fhost %>:load.load
-[<%= fhost %>] # linux box 
-       address <%= munin_host_real %>
-       port <%= munin_port_real %>
-       use_node_name yes
-    load.load.warning 5
-    load.load.critical 10
diff --git a/templates/snmpclient.erb b/templates/snmpclient.erb
deleted file mode 100644 (file)
index 44ecc6d..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<%
-       # Downcase all information
-       dom = domain.downcase
-       host = hostname.downcase
-       fhost = name.downcase
-%>
-### This syntax can be extended, it might get better ...
-#<%= dom %> snmp -> <%= fhost %>
-[<%= fhost %>] # snmp box 
-       address <%= munin_host_real %>