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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
#! /bin/sh
#
# Copyright (c) 1997,2003 Silicon Graphics, Inc. All Rights Reserved.
#
# 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.
#
# Install the shping PMDA and/or PMNS
#
. $PCP_DIR/etc/pcp.env
. $PCP_SHARE_DIR/lib/pmdaproc.sh
iam=shping
pmda_interface=2
forced_restart=false
# Do it
#
pmdaSetup
# controls for installation procedures
#
daemon_opt=true # can install as daemon
dso_opt=false
pipe_opt=true # supports pipe IPC
socket_opt=false # force pipe IPC
check_delay=10 # give the PMDA a chance to set itself up
# be careful that mortals cannot write any configuration files, as
# these would present a security problem
#
umask 022
# PMDA variables
#
tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1
configfile=""
cycle=120
timeout=20
debug=0
trap "rm -rf $tmp; exit" 0 1 2 3 15
_quit()
{
rm -rf $tmp
exit $1
}
do_debug=false
_parsedefaults()
{
echo "Extracting options from current installation ..."
while getopts D:I:d:l:t: c
do
case $c in
\?) echo "Warning: Unrecognized option in $PCP_PMCDCONF_PATH"
echo " Remove line for the $iam PMDA in $PCP_PMCDCONF_PATH and re-run ./Install"
_quit 2;;
D ) debug=$OPTARG;;
I ) cycle=$OPTARG;;
t ) timeout=$OPTARG;;
* ) ;;
esac
done
eval configfile='$'$OPTIND
}
if $do_pmda
then
# set options from $PCP_PMCDCONF_PATH, if possible
#
ans=`$PCP_AWK_PROG <$PCP_PMCDCONF_PATH '
$1 == "'$iam'" { printf "%s",$6
for (i=7;i<=NF;i++) printf " %s",$i
print ""
}'`
if [ ! -z "$ans" ]
then
_parsedefaults $ans
fi
default_configfile=./sample.conf
if fgrep "CONFIGURE-ME-PLEASE" $default_configfile >/dev/null
then
# nslookup(1) may be hiding, like for OpenIndiana
#
export PATH=$PATH:/usr/sbin
nslookup=`which nslookup 2>/dev/null`
if [ -z "$nslookup" ]
then
echo "Warning: cannot find nslookup"
nslookup=nslookup
fi
# sample configuration file needs a little customization
#
if [ -f /etc/resolv.conf ]
then
my_dns_server=`$PCP_AWK_PROG </etc/resolv.conf '$1 == "nameserver" { print $2; exit }'`
else
my_dns_server=`hostname`
fi
sed <$default_configfile >$tmp/tmp \
-e '/CONFIGURE-ME-PLEASE/d' \
-e "s@DEFAULT-DNS-SERVER@$my_dns_server@" \
-e "s@NSLOOKUP@$nslookup@"
cp $tmp/tmp $default_configfile
fi
# go figure out which configuration file to use ...
#
pmdaChooseConfigFile
if [ ! -f "$configfile" ]
then
$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to enter commands to create a new configuration file? [y] ""$PCP_ECHO_C"
read ans
if [ "X$ans" = "Xy" -o "X$ans" = "XY" -o -z "$ans" ]
then
configfile="$configdir/$iam.conf"
if [ -f $configfile ]
then
echo "Removing old configuration file \"$configfile\""
rm -f $configfile
if [ -f $configfile ]
then
echo "Cannot remove \"$configfile\""
_quit 1
fi
fi
echo
echo \
'Enter one ping specification per line, in the format
tag command line details
where the "tag" is a single unique word (no spaces) and the "command line
details" are the corresponding sh(1) command. For example
dns-self nslookup `hostname`
An empty line terminates the specification process and there must be at
least one specification.
'
args=""
touch $configfile
if [ ! -f $configfile ]
then
echo "Installation aborted."
_quit 1
fi
while [ ! -s "$configfile" ]
do
while true
do
$PCP_ECHO_PROG $PCP_ECHO_N "Tag Command: ""$PCP_ECHO_C"
read tag cmd
[ -z "$tag" ] && break
if grep "^$tag " $configfile >/dev/null
then
echo "Sorry, tag \"$tag\" already in use. Please try again."
continue
fi
echo "$tag $cmd" >>$configfile
done
done
else
echo ""
echo "Error: Abandoning installation as no configuration file was specified."
_quit 1
fi
fi
echo
echo "All commands are run one after another as a group and the group is run"
$PCP_ECHO_PROG $PCP_ECHO_N "once per \"cycle\" time. Enter the cycle time in seconds [$cycle] ""$PCP_ECHO_C"
read ans
if [ ! -z "$ans" ]
then
cycle=$ans
fi
echo
echo "Each command must complete within a timeout period, or it will be aborted"
$PCP_ECHO_PROG $PCP_ECHO_N "by the \"$iam\" PMDA. Enter the timeout period (in seconds) [$timeout] ""$PCP_ECHO_C"
read ans
if [ ! -z "$ans" ]
then
timeout=$ans
fi
if [ "$do_debug" = true ]
then
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Enter the debugging flag (see pmdbg(1)) [$debug] ""$PCP_ECHO_C"
read ans
if [ ! -z "$ans" ]
then
debug=$ans
fi
fi
args="-I $cycle -t $timeout -D $debug $configfile"
fi
pmdaInstall
_quit 0
|