xymon-ext-scripts

Check-in [82baa7134d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:import pkgaudit.sh
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 82baa7134ddbe077b7c98e42694d20443fb3dec8c133439dfdbcee5902753e94
User & Date: feld@feld.me 2015-01-14 01:47:05
Context
2015-01-14
02:23
Add fancy status icon and standard-ish verbiage check-in: 86fe3a1d4f user: root@vm.feld.me tags: master, trunk
01:47
import pkgaudit.sh check-in: 82baa7134d user: feld@feld.me tags: master, trunk
01:45
Initial commit check-in: 1c80d13ea9 user: github@feld.me tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added pkgaudit.sh.















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
#-
# Copyright (c) 2015 Mark Felder
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted providing that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

#
# Place this file in /usr/local/www/xymon/client/ext/
# Then, to activate simply append the following to 
# the /usr/local/www/xymon/client/etc/localclient.cfg file:
#
#[pkg]
#        ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
#        CMD $XYMONCLIENTHOME/ext/pkgaudit.sh
#        LOGFILE $XYMONCLIENTLOGS/pkgaudit.log
#        INTERVAL 5m
#
# Now restart the xymon client to start using it.

# These can be overridden in xymonclient.cfg
: ${PKGAUDIT_COLOR="yellow"};		# Set color when results are found
: ${PKGAUDIT_JAILS="NO"};		# Audit jails if they don't run their own xymon-client
					# This needs to be capitalized "YES" to enable
: ${PKGAUDIT_JAILGREP="poudriere"};	# Argument to egrep to remove jails with name patterns.

# Xymon doesn't have /usr/local in PATH
PATH=${PATH}:/usr/local/bin:/usr/local/sbin

# Don't edit below unless you know what you're doing
COLUMN=pkgaudit
COLOR=green
PKGAUDIT_FLAGS=""
TMPFILE="$(mktemp -t xymon-client-pkgaudit)"

if [ $? -ne 0 ]; then
	echo "$0: Can't create temp file, exiting..."
	exit 1
fi

# Check if the vuln.xml exists. If not, we'll force a fetch.
if [ ! -e /var/db/pkg/vuln.xml ]; then
    PKGAUDIT_FLAGS="-F"
fi

# If vuln.xml is older than 24h, we'll also force a fetch.
if [ "$(find /var/db/pkg/vuln.xml -mtime +24h)" != "" ]; then 
    PKGAUDIT_FLAGS="-F"; 
fi

# Build the pkg-audit message header for main host
echo "$(hostname) pkg audit status" >> ${TMPFILE}
echo "" >> ${TMPFILE}

# Run pkg audit and collect output for main host
pkg-static audit ${PKGAUDIT_FLAGS} >> ${TMPFILE} || export NONGREEN=1

# Check if we should run on jails too. Grep removes poudriere jails.
if [ ${PKGAUDIT_JAILS} = "YES" ]; then
	for i in $(jls | sed '1d' | egrep -v "${PKGAUDIT_JAILGREP}" | awk '{print $1}'); do
		JAILROOT=$(jls -j ${i} -h path | sed '1d')
		echo "" >> ${TMPFILE}
		echo "##############################" >> ${TMPFILE}
		echo "" >> ${TMPFILE}
		echo "jail $(jexec ${i} hostname) pkg audit status" >> ${TMPFILE}
		pkg-static -o PKG_DBDIR=${JAILROOT}/var/db/pkg audit -f /var/db/pkg/vuln.xml >> ${TMPFILE} || export NONGREEN=1
	done
fi

# Ingest all the pkg audit messages.
MSG=$(cat ${TMPFILE})

# NONGREEN was detected.
[ ${NONGREEN} ] && COLOR=${PKGAUDIT_COLOR}

# Report results to Xymon
${XYMON} ${XYMSRV} "status ${MACHINE}.${COLUMN} ${COLOR} $(date)

${MSG}
"

rm ${TMPFILE}

exit 0