Merge ~aggkolaitis/charm-nagios:change_nagios_gui_username into ~nagios-charmers/charm-nagios:master

Proposed by Angelos Kolaitis
Status: Merged
Approved by: Xav Paice
Approved revision: 06b9eee99d28253ea89b8c5f1ea1bfeb438d75cb
Merged at revision: e3e2f757faa38e825a0cbf38e90c0f1ce876679e
Proposed branch: ~aggkolaitis/charm-nagios:change_nagios_gui_username
Merge into: ~nagios-charmers/charm-nagios:master
Diff against target: 244 lines (+39/-35)
3 files modified
config.yaml (+8/-4)
hooks/templates/nagios-cgi.tmpl (+25/-28)
hooks/upgrade-charm (+6/-3)
Reviewer Review Type Date Requested Status
Andrea Ieri Approve
Stuart Bishop (community) Approve
Canonical IS Reviewers Pending
Nagios Charm developers Pending
Review via email: mp+374089@code.launchpad.net

Commit message

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

LP: 1671831

Description of the change

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

LP: 1671831

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Stuart Bishop (stub) wrote :

Looks good. Some minor issues inline, nothing particularly important. Still needs a ~nagios-charmers review.

review: Approve
Revision history for this message
Angelos Kolaitis (aggkolaitis) wrote :

Thanks for the initial review, the code should be OK now.

Revision history for this message
Andrea Ieri (aieri) wrote :

Looks good. Just a very minor nit inline.
Also, for the future: whitespace fixes are welcome, but I think it would be cleaner to keep them in a separate 'noop' commit.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision e3e2f757faa38e825a0cbf38e90c0f1ce876679e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 4ce0f18..f116659 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -104,8 +104,8 @@ options:
6 admin_pager:
7 type: string
8 default: pageroot@localhost
9- description: |
10- Email address used for the admin pager, used by $ADMINPAGER$ in
11+ description: >
12+ Email address used for the admin pager, used by $ADMINPAGER$ in
13 notification commands.
14 enable_pagerduty:
15 type: boolean
16@@ -137,6 +137,11 @@ options:
17 default: 1
18 description: |
19 Log messages to syslog as well as main file.
20+ nagiosadmin:
21+ type: string
22+ default: 'nagiosadmin'
23+ description: >
24+ Username for Nagios admin user.
25 password:
26 type: string
27 default: ''
28@@ -168,7 +173,7 @@ options:
29 type: string
30 description: |
31 A string to pass to the Nagios load monitoring command. Default is
32- to report warning at 5.0, 4.0 and 3.0 averages, critical at 10.0,
33+ to report warning at 5.0, 4.0 and 3.0 averages, critical at 10.0,
34 6.0 and 4.0.
35 pagerduty_notification_levels:
36 default: u,c,r
37@@ -206,4 +211,3 @@ options:
38 u - Unknown
39 w - Warning
40 o - OK
41-
42diff --git a/hooks/templates/nagios-cgi.tmpl b/hooks/templates/nagios-cgi.tmpl
43index 11cb275..443a1ed 100644
44--- a/hooks/templates/nagios-cgi.tmpl
45+++ b/hooks/templates/nagios-cgi.tmpl
46@@ -1,6 +1,6 @@
47 #################################################################
48 #
49-# CGI.CFG - Sample CGI Configuration File for Nagios
50+# CGI.CFG - Sample CGI Configuration File for Nagios
51 #
52 #################################################################
53
54@@ -72,9 +72,9 @@ nagios_check_command=/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/sta
55
56
57 # AUTHENTICATION USAGE
58-# This option controls whether or not the CGIs will use any
59+# This option controls whether or not the CGIs will use any
60 # authentication when displaying host and service information, as
61-# well as committing commands to Nagios for processing.
62+# well as committing commands to Nagios for processing.
63 #
64 # Read the HTML documentation to learn how the authorization works!
65 #
66@@ -116,7 +116,7 @@ use_ssl_authentication=0
67 # access to the CGIs has been authenticated in some manner! If you
68 # define this variable, anyone who has not authenticated to the web
69 # server will inherit all rights you assign to this user!
70-
71+
72 #default_user_name=guest
73
74
75@@ -129,7 +129,7 @@ use_ssl_authentication=0
76 # not use authorization. You may use an asterisk (*) to
77 # authorize any user who has authenticated to the web server.
78
79-authorized_for_system_information=nagiosadmin
80+authorized_for_system_information={{ nagiosadmin }}
81
82
83
84@@ -141,7 +141,7 @@ authorized_for_system_information=nagiosadmin
85 # an asterisk (*) to authorize any user who has authenticated
86 # to the web server.
87
88-authorized_for_configuration_information=nagiosadmin
89+authorized_for_configuration_information={{ nagiosadmin }}
90
91
92
93@@ -154,7 +154,7 @@ authorized_for_configuration_information=nagiosadmin
94 # You may use an asterisk (*) to authorize any user who has
95 # authenticated to the web server.
96
97-authorized_for_system_commands=nagiosadmin
98+authorized_for_system_commands={{ nagiosadmin }}
99
100
101
102@@ -169,11 +169,11 @@ authorized_for_system_commands=nagiosadmin
103
104 {%if ro_password%}
105 authorized_for_read_only=nagiosro
106-authorized_for_all_services=nagiosadmin,nagiosro
107-authorized_for_all_hosts=nagiosadmin,nagiosro
108+authorized_for_all_services={{ nagiosadmin }},nagiosro
109+authorized_for_all_hosts={{ nagiosadmin }},nagiosro
110 {% else %}
111-authorized_for_all_services=nagiosadmin
112-authorized_for_all_hosts=nagiosadmin
113+authorized_for_all_services={{ nagiosadmin }}
114+authorized_for_all_hosts={{ nagiosadmin }}
115 {% endif %}
116
117
118@@ -181,14 +181,14 @@ authorized_for_all_hosts=nagiosadmin
119 # GLOBAL HOST/SERVICE COMMAND ACCESS
120 # These two options are comma-delimited lists of all usernames that
121 # can issue host or service related commands via the command
122-# CGI (cmd.cgi) for all hosts and services that are being monitored.
123-# By default, users can only issue commands for hosts or services
124-# that they are contacts for (unless you you choose to not use
125+# CGI (cmd.cgi) for all hosts and services that are being monitored.
126+# By default, users can only issue commands for hosts or services
127+# that they are contacts for (unless you you choose to not use
128 # authorization). You may use an asterisk (*) to authorize any
129 # user who has authenticated to the web server.
130
131-authorized_for_all_service_commands=nagiosadmin
132-authorized_for_all_host_commands=nagiosadmin
133+authorized_for_all_service_commands={{ nagiosadmin }}
134+authorized_for_all_host_commands={{ nagiosadmin }}
135
136
137
138@@ -204,7 +204,7 @@ authorized_for_all_host_commands=nagiosadmin
139
140
141 # STATUSMAP BACKGROUND IMAGE
142-# This option allows you to specify an image to be used as a
143+# This option allows you to specify an image to be used as a
144 # background in the statusmap CGI. It is assumed that the image
145 # resides in the HTML images path (i.e. /usr/local/nagios/share/images).
146 # This path is automatically determined by appending "/images"
147@@ -222,7 +222,7 @@ authorized_for_all_host_commands=nagiosadmin
148 # STATUSMAP TRANSPARENCY INDEX COLOR
149 # These options set the r,g,b values of the background color used the statusmap CGI,
150 # so normal browsers that can't show real png transparency set the desired color as
151-# a background color instead (to make it look pretty).
152+# a background color instead (to make it look pretty).
153 # Defaults to white: (R,G,B) = (255,255,255).
154
155 #color_transparency_index_r=255
156@@ -263,7 +263,7 @@ default_statuswrl_layout=4
157
158
159 # STATUSWRL INCLUDE
160-# This option allows you to include your own objects in the
161+# This option allows you to include your own objects in the
162 # generated VRML world. It is assumed that the file
163 # resides in the HTML path (i.e. /usr/local/nagios/share).
164
165@@ -289,15 +289,15 @@ ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
166
167 # REFRESH RATE
168 # This option allows you to specify the refresh rate in seconds
169-# of various CGIs (status, statusmap, extinfo, and outages).
170+# of various CGIs (status, statusmap, extinfo, and outages).
171
172 refresh_rate=90
173
174 # DEFAULT PAGE LIMIT
175-# This option allows you to specify the default number of results
176+# This option allows you to specify the default number of results
177 # displayed on the status.cgi. This number can be adjusted from
178 # within the UI after the initial page load. Setting this to 0
179-# will show all results.
180+# will show all results.
181
182 result_limit=100
183
184@@ -339,7 +339,7 @@ escape_html_tags=1
185
186
187 # URL TARGET FRAMES
188-# These options determine the target frames in which notes and
189+# These options determine the target frames in which notes and
190 # action URLs will open.
191
192 action_url_target=_blank
193@@ -349,8 +349,8 @@ notes_url_target=_blank
194
195
196 # LOCK AUTHOR NAMES OPTION
197-# This option determines whether users can change the author name
198-# when submitting comments, scheduling downtime. If disabled, the
199+# This option determines whether users can change the author name
200+# when submitting comments, scheduling downtime. If disabled, the
201 # author names will be locked into their contact name, as defined in Nagios.
202 # Values: 0 = allow editing author names
203 # 1 = lock author names (disallow editing)
204@@ -378,6 +378,3 @@ lock_author_names=1
205 # This option should be the URL used to access your instance of Splunk
206
207 #splunk_url=http://127.0.0.1:8000/
208-
209-
210-
211diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
212index 19e736c..d70a368 100755
213--- a/hooks/upgrade-charm
214+++ b/hooks/upgrade-charm
215@@ -38,6 +38,7 @@ pagerduty_cfg = "/etc/nagios3/conf.d/pagerduty_nagios.cfg"
216 pagerduty_cron = "/etc/cron.d/nagios-pagerduty-flush"
217 password = hookenv.config('password')
218 ro_password = hookenv.config('ro-password')
219+nagiosadmin = hookenv.config('nagiosadmin') or 'nagiosadmin'
220
221
222 # Checks the charm relations for legacy relations
223@@ -284,7 +285,8 @@ def update_config():
224
225
226 def update_cgi_config():
227- template_values = {'ro_password': ro_password}
228+ template_values = {'nagiosadmin': nagiosadmin,
229+ 'ro_password': ro_password}
230 with open('hooks/templates/nagios-cgi.tmpl', 'r') as f:
231 templateDef = f.read()
232
233@@ -361,8 +363,9 @@ update_localhost()
234 update_cgi_config()
235 update_password('nagiosro', ro_password)
236 if password:
237- update_password('nagiosadmin', password)
238-
239+ update_password(nagiosadmin, password)
240+if nagiosadmin != 'nagiosadmin':
241+ update_password('nagiosadmin', False)
242
243 subprocess.call(['hooks/mymonitors-relation-joined'])
244 subprocess.call(['hooks/monitors-relation-changed'])

Subscribers

People subscribed via source and target branches