summaryrefslogtreecommitdiff
path: root/src/pmieconf/check-rules
blob: b61421d539a490a04484f61265df9ef30b22e8b5 (plain)
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
#!/bin/sh
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


# Once the "rules" directory is populated, extract all the PCP metric
# names and make sure they are available on the current host or the
# host specified by -h hostname
#

_usage()
{
    echo "Usage: $0 [-h hostname]"
    exit 1
}

source=''
while getopts "h:?" c
do
    case $c
    in
	h)
	    source="-h $OPTARG"
	    ;;
	?)
	    _usage
	    # NOTREACHED
	    ;;
    esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 0 ]
then
    _usage
    # NOTREACHED
fi

if [ ! -d rules ]
then
    echo "$0: cannot find \"rules\" directory!"
    exit 1
fi

find rules -follow -type f -print \
| LC_COLLATE=POSIX sort \
| while read rule
do
    badrule=false
    ./xtractnames <$rule \
    | while read metric
    do

	probe=`pmprobe $source $metric`
	numval=`echo $probe | awk '{print $2}'`
	if [ $numval -lt 0 ]
	then
	    if $badrule
	    then
		:
	    else
		echo
		echo "$rule"
		echo "#"
		echo "# rule: `basename $rule`"
		badrule=true
	    fi
	    echo "#   $probe"
	fi
    done
done