← Back to team overview

nagios-charmers team mailing list archive

[Merge] nagios-charm:flap-detection into nagios-charm:master

 

James Hebden has proposed merging nagios-charm:flap-detection into nagios-charm:master.

Commit message:
This merge introduces a new configuration item "flap_detection".
It controls whether or not flap detection is enabled in Nagios. The default is true, which matches the present hard-coded default in the Nagios configuration template.

Additionally, I have added a function to the hooks library that will convert a python boolean type (which is returned by hookenv.config for a boolean type config item) into Nagios's preferred 0/1 integer representation for on/off states. This new setting uses the function, but I have not altered the behaviour of any existing settings and their rendering into the configuration file. It simply typecasts the boolean type as int, which achieves the desired result.

Requested reviews:
  Nagios Charm developers (nagios-charmers)

For more details, see:
https://code.launchpad.net/~nagios-charmers/nagios-charm/+git/nagios-charm/+merge/375524
-- 
Your team Nagios Charm developers is requested to review the proposed merge of nagios-charm:flap-detection into nagios-charm:master.
diff --git a/config.yaml b/config.yaml
index 4ce0f18..da83582 100644
--- a/config.yaml
+++ b/config.yaml
@@ -6,6 +6,11 @@ options:
             Any additional nagios configuration you would like to
             add can be set into this element. It will be placed in
             /etc/nagios3/conf.d/extra.cfg
+    flap_detection:
+        type: boolean
+        default: true
+        description: |
+            Enable flap detection on monitored hosts and services.
     ssl:
         type: string
         default: "off"
diff --git a/hooks/templates/nagios-cfg.tmpl b/hooks/templates/nagios-cfg.tmpl
index c45ed31..2d202b2 100644
--- a/hooks/templates/nagios-cfg.tmpl
+++ b/hooks/templates/nagios-cfg.tmpl
@@ -1097,7 +1097,7 @@ additional_freshness_latency=15
 # Values: 1 = enable flap detection
 #         0 = disable flap detection (default)
 
-enable_flap_detection=1
+enable_flap_detection={{ flap_detection }}
 
 
 
diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
index 19e736c..9edf436 100755
--- a/hooks/upgrade-charm
+++ b/hooks/upgrade-charm
@@ -233,6 +233,11 @@ def enable_ssl():
         hookenv.log("Decoded SSL files", "INFO")
 
 
+def nagios_bool(value):
+    """Convert a Python boolean into Nagios 0/1 integer representation."""
+    return int(value)
+
+
 def update_config():
     host_context = hookenv.config('nagios_host_context')
     local_host_name = 'nagios'
@@ -254,6 +259,7 @@ def update_config():
                        'debug_verbosity': hookenv.config('debug_verbosity'),
                        'debug_level': hookenv.config('debug_level'),
                        'daemon_dumps_core': hookenv.config('daemon_dumps_core'),
+                       'flap_detection': nagios_bool(hookenv.config('flap_detection')),
                        'admin_email': hookenv.config('admin_email'),
                        'admin_pager': hookenv.config('admin_pager'),
                        'log_rotation_method': hookenv.config('log_rotation_method'),

Follow ups