Merge lp:~brad-marshall/charms/trusty/nrpe-external-master/add-conntrack-check into lp:charms/nrpe-external-master

Proposed by Brad Marshall
Status: Needs review
Proposed branch: lp:~brad-marshall/charms/trusty/nrpe-external-master/add-conntrack-check
Merge into: lp:charms/nrpe-external-master
Diff against target: 107 lines (+74/-0)
3 files modified
config.yaml (+4/-0)
files/check_conntrack.sh (+66/-0)
hooks/config-changed (+4/-0)
To merge this branch: bzr merge lp:~brad-marshall/charms/trusty/nrpe-external-master/add-conntrack-check
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+321412@code.launchpad.net

Description of the change

Add iptables conntrack nrpe check

To post a comment you must log in.

Unmerged revisions

43. By Brad Marshall

Added conntrack nrpe check

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-05-01 13:23:24 +0000
3+++ config.yaml 2017-03-30 07:26:20 +0000
4@@ -64,6 +64,10 @@
5 default: "-w 90% -c 75%"
6 type: string
7 description: Swap check
8+ conntrack:
9+ default: "-w 80 -c 90"
10+ type: string
11+ description: conntrack table check
12 hostgroups:
13 default: ""
14 type: string
15
16=== added file 'files/check_conntrack.sh'
17--- files/check_conntrack.sh 1970-01-01 00:00:00 +0000
18+++ files/check_conntrack.sh 2017-03-30 07:26:20 +0000
19@@ -0,0 +1,66 @@
20+#!/bin/sh
21+# This file is managed by juju. Do not make local changes.
22+
23+# Copyright (C) 2013, 2016 Canonical Ltd.
24+# Author: Haw Loeung <haw.loeung@canonical.com>
25+# Paul Gear <paul.gear@canonical.com>
26+
27+# Alert when current conntrack entries exceeds certain percentage of max. to
28+# detect when we're about to fill it up and start dropping packets.
29+
30+set -eu
31+
32+STATE_OK=0
33+STATE_WARNING=1
34+STATE_CRITICAL=2
35+STATE_UNKNOWN=3
36+
37+if ! lsmod | grep -q conntrack; then
38+ echo "OK: no conntrack modules present"
39+ exit $STATE_OK
40+fi
41+
42+max=$(sysctl net.netfilter.nf_conntrack_max | awk '{ print $3 }')
43+current=$(sysctl net.netfilter.nf_conntrack_count | awk '{ print $3 }')
44+
45+# default thresholds
46+crit=90
47+warn=80
48+
49+# parse command line
50+set +e
51+OPTIONS=$(getopt w:c: "$@")
52+if [ $? -ne 0 ]; then
53+ echo "Usage: $0 [-w warningpercent] [-c criticalpercent]" >&2
54+ echo " Check nf_conntrack_count against nf_conntrack_max" >&2
55+ exit $STATE_UNKNOWN
56+fi
57+set -e
58+
59+set -- $OPTIONS
60+while true; do
61+ case "$1" in
62+ -w) warn=$2; shift 2 ;;
63+ -c) crit=$2; shift 2 ;;
64+ --) shift; break ;;
65+ *) break ;;
66+ esac
67+done
68+
69+percent=$((current * 100 / max))
70+stats="| current=$current max=$max percent=$percent;$warn;$crit"
71+
72+threshold=$((max * crit / 100))
73+if [ $current -gt $threshold ]; then
74+ echo "CRITICAL: conntrack table nearly full. $stats"
75+ exit $STATE_CRITICAL
76+fi
77+
78+threshold=$((max * warn / 100))
79+if [ $current -gt $threshold ]; then
80+ echo "WARNING: conntrack table filling. $stats"
81+ exit $STATE_WARNING
82+fi
83+
84+echo "OK: conntrack table normal $stats"
85+exit $STATE_OK
86
87=== modified file 'hooks/config-changed'
88--- hooks/config-changed 2015-05-21 15:52:29 +0000
89+++ hooks/config-changed 2017-03-30 07:26:20 +0000
90@@ -41,6 +41,7 @@
91 LOAD=$(config-get load)
92 USERS=$(config-get users)
93 SWAP=$(config-get swap)
94+CONNTRACK=$(config-get conntrack)
95
96 if [[ "$PROCS" == "auto" ]]; then
97 PROC_COUNT=$(nproc)
98@@ -80,6 +81,9 @@
99 echo "# Swap" > /etc/nagios/nrpe.d/check_swap.cfg
100 echo "command[check_swap]=/usr/lib/nagios/plugins/check_swap ${SWAP}" >> /etc/nagios/nrpe.d/check_swap.cfg
101
102+echo "# Conntrack" > /etc/nagios/nrpe.d/check_conntrack.cfg
103+echo "command[check_conntrack]=/usr/local/lib/nagios/plugins/check_conntrack.sh ${CONNTRACK}" >> /etc/nagios/nrpe.d/check_conntrack.cfg
104+
105 #------------------------------------------------------
106 # Host check
107 #------------------------------------------------------

Subscribers

People subscribed via source and target branches

to all changes: