← Back to team overview

nagios-charmers team mailing list archive

[Merge] ~aggkolaitis/nagios-charm:change_nagios_gui_username into nagios-charm:master

 

Aggelos Kolaitis has proposed merging ~aggkolaitis/nagios-charm:change_nagios_gui_username into nagios-charm:master.

Commit message:
Added a configuration option to change default 'nagiosadmin' user name

LP: 1671831

Requested reviews:
  Canonical IS Reviewers (canonical-is-reviewers)
  Nagios Charm developers (nagios-charmers)
Related bugs:
  Bug #1671831 in Nagios Charm: "Allow for configuring of the web interface username "
  https://bugs.launchpad.net/nagios-charm/+bug/1671831

For more details, see:
https://code.launchpad.net/~aggkolaitis/nagios-charm/+git/nagios-charm/+merge/374089

Added a configuration option to change default 'nagiosadmin' user name

LP: 1671831
-- 
Your team Nagios Charm developers is requested to review the proposed merge of ~aggkolaitis/nagios-charm:change_nagios_gui_username into nagios-charm:master.
diff --git a/config.yaml b/config.yaml
index 4ce0f18..03c270e 100644
--- a/config.yaml
+++ b/config.yaml
@@ -105,7 +105,7 @@ options:
         type: string
         default: pageroot@localhost
         description: |
-            Email address used for the admin pager, used by $ADMINPAGER$ in 
+            Email address used for the admin pager, used by $ADMINPAGER$ in
             notification commands.
     enable_pagerduty:
         type: boolean
@@ -137,6 +137,11 @@ options:
         default: 1
         description: |
             Log messages to syslog as well as main file.
+    nagiosadmin:
+        type: string
+        default: 'nagiosadmin'
+        description: |
+            Username for Nagios admin user.
     password:
         type: string
         default: ''
@@ -168,7 +173,7 @@ options:
         type: string
         description: |
             A string to pass to the Nagios load monitoring command.  Default is
-            to report warning at 5.0, 4.0 and 3.0 averages, critical at 10.0, 
+            to report warning at 5.0, 4.0 and 3.0 averages, critical at 10.0,
             6.0 and 4.0.
     pagerduty_notification_levels:
         default: u,c,r
@@ -206,4 +211,3 @@ options:
             u - Unknown
             w - Warning
             o - OK
-
diff --git a/hooks/templates/nagios-cgi.tmpl b/hooks/templates/nagios-cgi.tmpl
index 11cb275..443a1ed 100644
--- a/hooks/templates/nagios-cgi.tmpl
+++ b/hooks/templates/nagios-cgi.tmpl
@@ -1,6 +1,6 @@
 #################################################################
 #
-# CGI.CFG - Sample CGI Configuration File for Nagios 
+# CGI.CFG - Sample CGI Configuration File for Nagios
 #
 #################################################################
 
@@ -72,9 +72,9 @@ nagios_check_command=/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/sta
 
 
 # AUTHENTICATION USAGE
-# This option controls whether or not the CGIs will use any 
+# This option controls whether or not the CGIs will use any
 # authentication when displaying host and service information, as
-# well as committing commands to Nagios for processing.  
+# well as committing commands to Nagios for processing.
 #
 # Read the HTML documentation to learn how the authorization works!
 #
@@ -116,7 +116,7 @@ use_ssl_authentication=0
 # access to the CGIs has been authenticated in some manner!  If you
 # define this variable, anyone who has not authenticated to the web
 # server will inherit all rights you assign to this user!
- 
+
 #default_user_name=guest
 
 
@@ -129,7 +129,7 @@ use_ssl_authentication=0
 # not use authorization.  You may use an asterisk (*) to
 # authorize any user who has authenticated to the web server.
 
-authorized_for_system_information=nagiosadmin
+authorized_for_system_information={{ nagiosadmin }}
 
 
 
@@ -141,7 +141,7 @@ authorized_for_system_information=nagiosadmin
 # an asterisk (*) to authorize any user who has authenticated
 # to the web server.
 
-authorized_for_configuration_information=nagiosadmin
+authorized_for_configuration_information={{ nagiosadmin }}
 
 
 
@@ -154,7 +154,7 @@ authorized_for_configuration_information=nagiosadmin
 # You may use an asterisk (*) to authorize any user who has
 # authenticated to the web server.
 
-authorized_for_system_commands=nagiosadmin
+authorized_for_system_commands={{ nagiosadmin }}
 
 
 
@@ -169,11 +169,11 @@ authorized_for_system_commands=nagiosadmin
 
 {%if ro_password%}
 authorized_for_read_only=nagiosro
-authorized_for_all_services=nagiosadmin,nagiosro
-authorized_for_all_hosts=nagiosadmin,nagiosro
+authorized_for_all_services={{ nagiosadmin }},nagiosro
+authorized_for_all_hosts={{ nagiosadmin }},nagiosro
 {% else %}
-authorized_for_all_services=nagiosadmin
-authorized_for_all_hosts=nagiosadmin
+authorized_for_all_services={{ nagiosadmin }}
+authorized_for_all_hosts={{ nagiosadmin }}
 {% endif %}
 
 
@@ -181,14 +181,14 @@ authorized_for_all_hosts=nagiosadmin
 # GLOBAL HOST/SERVICE COMMAND ACCESS
 # These two options are comma-delimited lists of all usernames that
 # can issue host or service related commands via the command
-# CGI (cmd.cgi) for all hosts and services that are being monitored. 
-# By default, users can only issue commands for hosts or services 
-# that they are contacts for (unless you you choose to not use 
+# CGI (cmd.cgi) for all hosts and services that are being monitored.
+# By default, users can only issue commands for hosts or services
+# that they are contacts for (unless you you choose to not use
 # authorization).  You may use an asterisk (*) to authorize any
 # user who has authenticated to the web server.
 
-authorized_for_all_service_commands=nagiosadmin
-authorized_for_all_host_commands=nagiosadmin
+authorized_for_all_service_commands={{ nagiosadmin }}
+authorized_for_all_host_commands={{ nagiosadmin }}
 
 
 
@@ -204,7 +204,7 @@ authorized_for_all_host_commands=nagiosadmin
 
 
 # STATUSMAP BACKGROUND IMAGE
-# This option allows you to specify an image to be used as a 
+# This option allows you to specify an image to be used as a
 # background in the statusmap CGI.  It is assumed that the image
 # resides in the HTML images path (i.e. /usr/local/nagios/share/images).
 # This path is automatically determined by appending "/images"
@@ -222,7 +222,7 @@ authorized_for_all_host_commands=nagiosadmin
 # STATUSMAP TRANSPARENCY INDEX COLOR
 # These options set the r,g,b values of the background color used the statusmap CGI,
 # so normal browsers that can't show real png transparency set the desired color as
-# a background color instead (to make it look pretty).  
+# a background color instead (to make it look pretty).
 # Defaults to white: (R,G,B) = (255,255,255).
 
 #color_transparency_index_r=255
@@ -263,7 +263,7 @@ default_statuswrl_layout=4
 
 
 # STATUSWRL INCLUDE
-# This option allows you to include your own objects in the 
+# This option allows you to include your own objects in the
 # generated VRML world.  It is assumed that the file
 # resides in the HTML path (i.e. /usr/local/nagios/share).
 
@@ -289,15 +289,15 @@ ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
 
 # REFRESH RATE
 # This option allows you to specify the refresh rate in seconds
-# of various CGIs (status, statusmap, extinfo, and outages).  
+# of various CGIs (status, statusmap, extinfo, and outages).
 
 refresh_rate=90
 
 # DEFAULT PAGE LIMIT
-# This option allows you to specify the default number of results 
+# This option allows you to specify the default number of results
 # displayed on the status.cgi.  This number can be adjusted from
 # within the UI after the initial page load. Setting this to 0
-# will show all results.  
+# will show all results.
 
 result_limit=100
 
@@ -339,7 +339,7 @@ escape_html_tags=1
 
 
 # URL TARGET FRAMES
-# These options determine the target frames in which notes and 
+# These options determine the target frames in which notes and
 # action URLs will open.
 
 action_url_target=_blank
@@ -349,8 +349,8 @@ notes_url_target=_blank
 
 
 # LOCK AUTHOR NAMES OPTION
-# This option determines whether users can change the author name 
-# when submitting comments, scheduling downtime.  If disabled, the 
+# This option determines whether users can change the author name
+# when submitting comments, scheduling downtime.  If disabled, the
 # author names will be locked into their contact name, as defined in Nagios.
 # Values: 0 = allow editing author names
 #         1 = lock author names (disallow editing)
@@ -378,6 +378,3 @@ lock_author_names=1
 # This option should be the URL used to access your instance of Splunk
 
 #splunk_url=http://127.0.0.1:8000/
-
-
-
diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
index 19e736c..e154b85 100755
--- a/hooks/upgrade-charm
+++ b/hooks/upgrade-charm
@@ -284,7 +284,8 @@ def update_config():
 
 
 def update_cgi_config():
-    template_values = {'ro_password': ro_password}
+    template_values = {'nagiosadmin': hookenv.config('nagiosadmin'),
+                       'ro_password': ro_password}
     with open('hooks/templates/nagios-cgi.tmpl', 'r') as f:
         templateDef = f.read()
 
@@ -361,8 +362,9 @@ update_localhost()
 update_cgi_config()
 update_password('nagiosro', ro_password)
 if password:
-    update_password('nagiosadmin', password)
-
+    update_password(hookenv.config('nagiosadmin'), password)
+if hookenv.config('nagiosadmin') != 'nagiosadmin':
+    update_password('nagiosadmin', False)
 
 subprocess.call(['hooks/mymonitors-relation-joined'])
 subprocess.call(['hooks/monitors-relation-changed'])

References