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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!/bin/sh
# PCP QA Test No. 1160
# Exercise PCP netcheck PMDA ping modules - install, remove and values.
#
# Copyright (c) 2019 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"
. ./common.python
$python -c "from pcp import pmda" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmda module not installed"
$python -c "import importlib" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python importlib module not installed"
[ -f $PCP_PMDAS_DIR/netcheck/Install ] || _notrun "netcheck PMDA not installed"
which ping > /dev/null 2>&1 || _notrun "ping not installed"
ping -c 1 localhost > /dev/null 2>&1 || _notrun "failed to ping localhost"
selinux=$(getenforce 2>/dev/null)
pgr=0
if [ -f /proc/sys/net/ipv4/ping_group_range ]; then
pgr=$(tr -d '\t' < /proc/sys/net/ipv4/ping_group_range 2>/dev/null)
fi
if [ "$selinux" = "Enforcing" -a $pgr -eq 10 ]; then
seinfo --common > /dev/null 2>&1 && scf=--common
seinfo -x --class=icmp_socket $scf 2>/dev/null \
| grep '^[ ][ ]*class icmp_socket$' >/dev/null && icmp_cls=true
fi
if [ "$selinux" = "Enforcing" -a $pgr -eq 10 -a "$icmp_cls" = "true" ]; then
_notrun "ping_group_range does not allow creating ICMP Echo sockets"
fi
status=1 # failure is the default!
signal=$PCP_BINADM_DIR/pmsignal
pmda_filter()
{
sed \
-e "s/.*Info:/Info:/g" \
-e "s/\[.* or /\[X or /g" \
-e "s/value [0-3].*/value OK/g" \
-e "s/u'\([^']*\)'/'\1'/g" \
#end
}
pmda_remove()
{
echo
echo "=== remove netcheck agent ==="
$sudo ./Remove >$tmp.out 2>&1
_filter_pmda_remove <$tmp.out \
| sed \
-e '/ Info: /d' \
# end
}
pmda_install()
{
# start from known starting points
cd $PCP_PMDAS_DIR/netcheck
$sudo ./Remove >/dev/null 2>&1
cat <<EOF >$tmp.config
[pmda]
modules = ping,ping_latency,ping_loss
hosts = localhost
background_check = False
[ping]
count = 1
timeout = 1
[ping_latency]
count = 1
timeout = 1
[ping_loss]
count = 1
timeout = 1
EOF
echo "pmdanetcheck config:" >> $seq_full
cat $tmp.config >> $seq_full
[ -f $PCP_PMDAS_DIR/netcheck/netcheck.conf ] && \
$sudo cp $PCP_PMDAS_DIR/netcheck/netcheck.conf $tmp.backup
$sudo cp $tmp.config $PCP_PMDAS_DIR/netcheck/netcheck.conf
echo
echo "=== netcheck agent installation ==="
$sudo ./Install < /dev/null >$tmp.out 2>&1
cat $tmp.out | _filter_pmda_install | pmda_filter
}
pmda_cleanup()
{
if [ -f $tmp.backup ]; then
$sudo cp $tmp.backup $PCP_PMDAS_DIR/netcheck/netcheck.conf
$sudo rm $tmp.backup
else
$sudo rm -f $PCP_PMDAS_DIR/netcheck/netcheck.conf
fi
# note: _restore_auto_restart pmcd done in _cleanup_pmda()
_cleanup_pmda netcheck
}
_prepare_pmda netcheck
trap "pmda_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd
# real QA test starts here
rm -f $tmp.stats
pmda_install
echo
echo "=== report metric values ==="
metrics=`pminfo netcheck | LC_COLLATE=POSIX sort`
pminfo -dfmtT $metrics 2>&1 \
| pmda_filter | tee -a $seq_full
echo "=== verify metric values ==="
pminfo -v netcheck 2>&1 \
| pmda_filter | tee -a $seq_full
pmda_remove
status=0
exit
|