Merge lp:~thedac/charms/precise/pgbouncer/nagios-check-fixes into lp:charms/pgbouncer

Proposed by David Ames
Status: Merged
Merged at revision: 59
Proposed branch: lp:~thedac/charms/precise/pgbouncer/nagios-check-fixes
Merge into: lp:charms/pgbouncer
Diff against target: 184 lines (+67/-14)
7 files modified
config.yaml (+6/-0)
hooks/config-changed (+2/-0)
hooks/db-proxy-relation-changed (+2/-2)
hooks/install (+2/-0)
hooks/nrpe-external-master-relation-changed (+36/-11)
revision (+1/-1)
scripts/common (+18/-0)
To merge this branch: bzr merge lp:~thedac/charms/precise/pgbouncer/nagios-check-fixes
Reviewer Review Type Date Requested Status
Dave Cheney (community) lgtm Approve
charmers Pending
Review via email: mp+183250@code.launchpad.net

Description of the change

Setup nagios .pgpass and userlist.txt entry for nagios checks

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) :
review: Approve (lgtm)
Revision history for this message
David Ames (thedac) wrote :

Dave,

Any chance you can merge this. Matthew will not have to time to do a review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2013-02-25 05:22:47 +0000
+++ config.yaml 2013-08-30 18:41:25 +0000
@@ -149,6 +149,12 @@
149 type: string149 type: string
150 description: |150 description: |
151 What service this component forms part of. Used by nrpe.151 What service this component forms part of. Used by nrpe.
152 package_status:
153 default: "install"
154 type: string
155 description: |
156 The status of service-affecting packages will be set to this value in the dpkg database.
157 Useful valid values are "install" and "hold".
152 wait_warn:158 wait_warn:
153 default: 5159 default: 5
154 type: int160 type: int
155161
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2012-10-02 08:57:36 +0000
+++ hooks/config-changed 2013-08-30 18:41:25 +0000
@@ -11,5 +11,7 @@
11juju-log "Generating new pgbouncer configuration and init script"11juju-log "Generating new pgbouncer configuration and init script"
12update_config12update_config
1313
14ensure_package_status "${SERVICE_AFFECTING_PACKAGES}" $(config-get package_status)
15
14juju-log "Reloading pgbouncer"16juju-log "Reloading pgbouncer"
15/usr/sbin/service pgbouncer reload17/usr/sbin/service pgbouncer reload
1618
=== modified file 'hooks/db-proxy-relation-changed'
--- hooks/db-proxy-relation-changed 2013-03-22 14:30:59 +0000
+++ hooks/db-proxy-relation-changed 2013-08-30 18:41:25 +0000
@@ -113,8 +113,8 @@
113if [ "$JUJU_RELATION" != "db-proxy" ]; then113if [ "$JUJU_RELATION" != "db-proxy" ]; then
114 # If called out of context114 # If called out of context
115 juju-log "Out of db-proxy relation context, manually setting JUJU vars for db-proxy relation"115 juju-log "Out of db-proxy relation context, manually setting JUJU vars for db-proxy relation"
116 JUJU_RELATION="db-proxy"116 export JUJU_RELATION="db-proxy"
117 export JUJU_RELATION_IDS=$(relation-ids db-proxy)117 JUJU_RELATION_IDS=$(relation-ids db-proxy)
118 UPDATED="False" 118 UPDATED="False"
119 for JUJU_RELATION_ID in $(echo ${JUJU_RELATION_ID}); do119 for JUJU_RELATION_ID in $(echo ${JUJU_RELATION_ID}); do
120 export JUJU_REMOTE_UNIT=$(relation-list -r $JUJU_RELATION_ID)120 export JUJU_REMOTE_UNIT=$(relation-list -r $JUJU_RELATION_ID)
121121
=== modified file 'hooks/install'
--- hooks/install 2013-01-03 18:15:45 +0000
+++ hooks/install 2013-08-30 18:41:25 +0000
@@ -22,6 +22,8 @@
22juju-log "Installing packages via apt-get"22juju-log "Installing packages via apt-get"
23apt-get -y install -- pgbouncer python-cheetah postgresql-client pwgen python-psycopg223apt-get -y install -- pgbouncer python-cheetah postgresql-client pwgen python-psycopg2
2424
25ensure_package_status "${SERVICE_AFFECTING_PACKAGES}" $(config-get package_status)
26
25# Make sure pgbouncer is enabled and set max open files27# Make sure pgbouncer is enabled and set max open files
26max_open_files=$(config-get max_open_files)28max_open_files=$(config-get max_open_files)
27cat >/etc/default/pgbouncer << EOF29cat >/etc/default/pgbouncer << EOF
2830
=== modified file 'hooks/nrpe-external-master-relation-changed'
--- hooks/nrpe-external-master-relation-changed 2013-02-25 07:15:10 +0000
+++ hooks/nrpe-external-master-relation-changed 2013-08-30 18:41:25 +0000
@@ -3,6 +3,9 @@
3# Copyright 2012 Canonical Ltd. All rights reserved.3# Copyright 2012 Canonical Ltd. All rights reserved.
4# Author: Haw Loeung <haw.loeung@canonical.com>4# Author: Haw Loeung <haw.loeung@canonical.com>
55
6set -eux # -x for verbose logging to juju debug-log
7. scripts/common
8
6unit_name=${JUJU_UNIT_NAME////-}9unit_name=${JUJU_UNIT_NAME////-}
7nagios_hostname="$(config-get nagios_context)-${unit_name}" 10nagios_hostname="$(config-get nagios_context)-${unit_name}"
8nagios_logdir='/var/log/nagios'11nagios_logdir='/var/log/nagios'
@@ -10,29 +13,29 @@
10nagios_servicegroup=$(config-get nagios_context)13nagios_servicegroup=$(config-get nagios_context)
11address=$(config-get listen_addr)14address=$(config-get listen_addr)
12if [ "$address" = "*" ]; then15if [ "$address" = "*" ]; then
13 address=$(unit-get private-address)16 address=$(unit-get private-address)
14fi17fi
1518
16nagios_uid=$(getent passwd nagios | awk -F: '{ print $3}')19nagios_uid=$(getent passwd nagios | awk -F: '{ print $3}')
17nagios_gid=$(getent passwd nagios | awk -F: '{ print $4}')20nagios_gid=$(getent passwd nagios | awk -F: '{ print $4}')
18if [ $? -ne 0 ]; then21if [ $? -ne 0 ]; then
19 juju-log "Nagios user not setup, exiting"22 juju-log "Nagios user not setup, exiting"
20 exit 123 exit 1
21fi24fi
2225
23if [ -d /usr/local/lib/nagios/plugins/ ]; then26if [ -d /usr/local/lib/nagios/plugins/ ]; then
24 cp $CHARM_DIR/scripts/check-pgbouncer.py $nagios_check_script27 cp $CHARM_DIR/scripts/check-pgbouncer.py $nagios_check_script
25 chmod 755 $nagios_check_script28 chmod 755 $nagios_check_script
26fi29fi
2730
28if [ ! -d $nagios_logdir ]; then31if [ ! -d $nagios_logdir ]; then
29 mkdir $nagios_logdir32 mkdir $nagios_logdir
30 chown nagios:nagios $nagios_logdir 33 chown nagios:nagios $nagios_logdir
31fi34fi
3235
33# Remove existing checks to start clean36# Remove existing checks to start clean
34for FILE in /var/lib/nagios/export/*check_pgbouncer*.cfg; do37for FILE in /var/lib/nagios/export/*check_pgbouncer*.cfg; do
35 rm -f $FILE38 rm -f $FILE
36done39done
3740
38# Export Juju configs and relations.41# Export Juju configs and relations.
@@ -63,10 +66,32 @@
63# Clean up66# Clean up
64rm -f $juju_configs67rm -f $juju_configs
6568
69# Create nagios user in pgbouncer
70nagios_home=$(getent passwd nagios | awk -F: '{ print $6 }')
71if [ ! -f ${nagios_home}/.pgpass ] || [ ! -f /var/lib/juju/nagios.password ]; then
72 password=$(pwgen -s 16)
73 nagios_home=$(getent passwd nagios | awk -F: '{ print $6 }')
74 if [ -d $nagios_home ]; then
75 echo "*:*:*:nagios:${password}" > ${nagios_home}/.pgpass
76 chown nagios:nagios ${nagios_home}/.pgpass
77 chmod 600 ${nagios_home}/.pgpass
78 else
79 juju-log "No home directory for nagios"
80 exit 1
81 fi
82 if [ -d /var/lib/juju/ ]; then
83 echo "${password}" > /var/lib/juju/nagios.password
84 update_config
85 else
86 juju-log "No /var/lib/juju directory"
87 exit 1
88 fi
89fi
90
66# Reload NRPE91# Reload NRPE
67if [ -x /etc/init.d/nagios-nrpe-server ]; then92if [ -x /etc/init.d/nagios-nrpe-server ]; then
68 service nagios-nrpe-server reload93 service nagios-nrpe-server reload
69else94else
70 juju-log "Is NRPE installed?"95 juju-log "Is NRPE installed?"
71 exit 196 exit 1
72fi97fi
7398
=== modified file 'revision'
--- revision 2013-02-25 05:23:43 +0000
+++ revision 2013-08-30 18:41:25 +0000
@@ -1,1 +1,1 @@
1112
22
=== modified file 'scripts/common'
--- scripts/common 2013-02-27 03:43:44 +0000
+++ scripts/common 2013-08-30 18:41:25 +0000
@@ -7,6 +7,8 @@
77
8set -eux # -x for verbose logging to juju debug-log8set -eux # -x for verbose logging to juju debug-log
99
10SERVICE_AFFECTING_PACKAGES="pgbouncer"
11
10update_config()12update_config()
11{13{
12 pgbouncer_userlist=/etc/pgbouncer/userlist.txt14 pgbouncer_userlist=/etc/pgbouncer/userlist.txt
@@ -50,3 +52,19 @@
50 juju-log "reloading pgbouncer"52 juju-log "reloading pgbouncer"
51 service pgbouncer reload || exit 153 service pgbouncer reload || exit 1
52}54}
55
56ensure_package_status()
57{
58 packages="$1" ; shift
59 status="$1" ; shift
60
61 case $status in
62 install|hold)
63 for package in ${packages}; do
64 echo ${package} ${status}
65 done | dpkg --set-selections
66 ;;
67 *)
68 ;;
69 esac
70}

Subscribers

People subscribed via source and target branches

to all changes: