Merge lp:~chris-gondolin/charms/precise/nrpe-external-master/trunk into lp:charms/nrpe-external-master

Proposed by Chris Stratford
Status: Merged
Approved by: JuanJo Ciarlante
Approved revision: 28
Merged at revision: 28
Proposed branch: lp:~chris-gondolin/charms/precise/nrpe-external-master/trunk
Merge into: lp:charms/nrpe-external-master
Diff against target: 34 lines (+16/-1)
1 file modified
hooks/config-changed (+16/-1)
To merge this branch: bzr merge lp:~chris-gondolin/charms/precise/nrpe-external-master/trunk
Reviewer Review Type Date Requested Status
JuanJo Ciarlante (community) Approve
Review via email: mp+205189@code.launchpad.net

Description of the change

The charm currently assumes "unit-get private-address" returns an IP address. This isn't always the case. This change attempts to ensure that $IPADDRESS really is an IP address (specifically an IPv4 address), so that the Nagios host check uses that IP address and does not rely on the results of a DNS lookup (which can return multiple addresses)

To post a comment you must log in.
Revision history for this message
JuanJo Ciarlante (jjo) wrote :

LGTM, please address this 1 ~nit, consider 1 suggestion:
1) please anchor the regex, to be: '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
2) if you want, you could do: host -4 -t a ${addr} | awk 'NR==1 { print $NF }'

review: Approve
27. By Chris Stratford

[chriss] Add jjo's suggested get_ipaddress improvements

28. By Chris Stratford

[chriss] Another jjo tweak

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/config-changed'
2--- hooks/config-changed 2013-08-30 22:10:07 +0000
3+++ hooks/config-changed 2014-02-07 11:31:06 +0000
4@@ -1,6 +1,21 @@
5 #!/bin/bash
6 set -eux
7
8+# Try to ensure we have an IP address, not a hostname
9+function get_ipaddress {
10+ local addr=${1:?}
11+ echo $addr | egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
12+ if [ $? -ne 0 ]; then
13+ # Could be a hostname
14+ addr=$(host -4 -t a ${addr} | awk 'NR==1 { print $NF }')
15+ if [ ${addr} = "3(NXDOMAIN)" ]; then
16+ # Maybe not, return the original input just to be safe
17+ addr=$1
18+ fi
19+ fi
20+ echo ${addr}
21+}
22+
23 #-----------------------------------------------------
24 # nrpe.cfg and rsyncd.conf
25 #-----------------------------------------------------
26@@ -69,7 +84,7 @@
27 fi
28 export NAGIOS_HOSTNAME="$(config-get nagios_host_context)-${RELATION}"
29 export NAGIOS_HOSTNAME=${NAGIOS_HOSTNAME//\//-}
30-export IPADDRESS=$(unit-get private-address)
31+export IPADDRESS=$(get_ipaddress $(unit-get private-address))
32 export HOSTCHECK_INHERIT=$(config-get hostcheck_inherit)
33 export HOSTGROUPS=$(config-get hostgroups)
34 cheetah fill --env --oext compiled templates/host.cfg.tmpl

Subscribers

People subscribed via source and target branches

to all changes: