OSDN Git Service

add check swap usage flag for localhost.
authorwhitestar <whitestar@users.osdn.me>
Wed, 5 Jan 2022 13:30:48 +0000 (22:30 +0900)
committerwhitestar <whitestar@users.osdn.me>
Wed, 5 Jan 2022 13:30:48 +0000 (22:30 +0900)
cookbooks/nagios-grid/CHANGELOG.md
cookbooks/nagios-grid/README.md
cookbooks/nagios-grid/attributes/default.rb
cookbooks/nagios-grid/recipes/nagios-base.rb
cookbooks/nagios-grid/version

index 436ae7c..66d7835 100644 (file)
@@ -1,6 +1,10 @@
 nagios-grid CHANGELOG
 =====================
 
+0.3.0
+-----
+- add check swap usage flag for localhost.
+
 0.2.0
 -----
 - add Nagios4 support.
index 608004e..92acf84 100644 (file)
@@ -50,6 +50,7 @@ None.
 |`['nagios']['web']['mod_auth_kerb']['Krb5Keytab']`|String||`'/etc/krb5.keytab'`|
 |`['nagios']['web']['mod_auth_kerb']['KrbMethodNegotiate']`|String||`'on'`|
 |`['nagios']['web']['mod_auth_kerb']['KrbMethodK5Passwd']`|String||`'off'`|
+|`['nagios']['localhost']['check_swap_usage']['enabled']`|Boolean||`true`|
 |`['nagios']['objects']['default_contact_groups']`|String||`'admins'`|
 |`['nagios']['objects']['check_ldap']['base']`|String||`'dc=example,dc=com'`|
 |`['nagios']['objects']['commands']`|Array|for full customization.|`[]`|
@@ -102,7 +103,7 @@ None.
 - Author:: whitestar at osdn.jp
 
 ```text
-Copyright 2016-2018, whitestar
+Copyright 2016-2022, whitestar
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
index c06df79..fec2c8b 100644 (file)
@@ -2,7 +2,7 @@
 # Cookbook Name:: nagios-grid
 # Attributes:: default
 #
-# Copyright 2016, whitestar
+# Copyright 2016-2022, whitestar
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -75,6 +75,8 @@ default['nagios']['web']['mod_auth_kerb']['KrbMethodNegotiate'] = 'on'
 default['nagios']['web']['mod_auth_kerb']['KrbMethodK5Passwd'] = 'off'
 
 # objects
+## localhost
+default['nagios']['localhost']['check_swap_usage']['enabled'] = true 
 ## default template base
 default['nagios']['objects']['default_contact_groups'] = 'admins'
 default['nagios']['objects']['check_ldap'] = {
index bdb551e..fa0ef8c 100644 (file)
@@ -2,7 +2,7 @@
 # Cookbook Name:: nagios-grid
 # Recipe:: nagios-base
 #
-# Copyright 2016-2018, whitestar
+# Copyright 2016-2022, whitestar
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -287,3 +287,17 @@ file '/usr/lib/nagios/plugins/check_disk_smb' do
   only_if { File.exist?(path) }
   notifies :restart, "service[#{nagios_service}]", :delayed if autoreload
 end
+
+# toggle swap usage check on localhost.
+file '/etc/nagios4/objects/localhost.cfg' do
+  content lazy {
+    cmd = Chef::Util::FileEdit.new(File.exist?(path) ? path : '/dev/null')
+    cmd.search_file_delete_line(/^\s+register\s+0$/)
+    unless node['nagios']['localhost']['check_swap_usage']['enabled']
+      cmd.insert_line_after_match(/^\s+service_description\s+Swap Usage$/, "        register    0\n")
+    end
+    cmd.send(:editor).lines.join('')
+  }
+  only_if { File.exist?(path) }
+  notifies :restart, "service[#{nagios_service}]", :delayed if autoreload
+end