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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
#! /bin/sh
#
# Copyright (c) 2000,2003,2004 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 weblog PMDA and/or PMNS
#
. $PCP_DIR/etc/pcp.env
. $PCP_SHARE_DIR/lib/pmdaproc.sh
# Override function from pmdaproc.sh
__choose_mode()
{
if [ -n "$QUIET_INSTALL" ] ; then
do_pmda=true
else
__def=m
$do_pmda && __def=b
echo \
'You will need to choose an appropriate configuration for installation of
the "'$iam'" Performance Metrics Domain Agent (PMDA).
collector collect performance statistics on this system
monitor allow this system to monitor local and/or remote systems
both collector and monitor configuration for this system
'
while true
do
$PCP_ECHO_PROG $PCP_ECHO_N 'Please enter c(ollector) or m(onitor) or b(oth) ['$__def'] '"$PCP_ECHO_C"
read ans
case "$ans"
in
"") break
;;
c|collector|b|both)
do_pmda=true
break
;;
m|monitor)
do_pmda=false
break
;;
*) echo "Sorry, that is not acceptable response ..."
;;
esac
done
echo
fi
}
iam=weblog
pmda_interface=2
forced_restart=false
pmdaSetup
pmns_name=web # metric names differ from PMDA name
daemon_opt=true # can install as daemon
dso_opt=false
pipe_opt=true # pipe IPC - YES
socket_opt=false # socket IPC - NO
socket_inet_def=2080 # default TCP port for Internet socket IPC
check_delay=10 # give the PMDA a chance to set itself up
# PMDA specific constants
#
configDir=$PCP_VAR_DIR/config/web
# PMDA variables
#
tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1
trap "rm -rf $tmp; exit" 0 1 2 3 15
debugFlag=0
do_debug=false
configFile=""
delay=15
chkDelay=20
maxserv=80
# --- start functions ---
#
_parseDefaults()
{
echo "Extracting options from current installation ..."
while getopts D:d:i:l:n:pS:t:u: c
do
case $c in
\?) echo "Warning: Unrecognized option in $PCP_PMCDCONF_PATH"
echo " Remove line for pmdaweblog in $PCP_PMCDCONF_PATH and re-run ./Install"
exit 2;;
D) debugFlag=$OPTARG;;
n) chkDelay=$OPTARG;;
t) delay=$OPTARG;;
S) maxserv=$OPTARG;;
*) # old or boring flags, silently ignore
;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -eq 1 ]
then
configFile=$1
elif [ $# -eq 0 ]
then
configFile=""
else
echo "Warning: unrecognized format for old specification in $PCP_PMCDCONF_PATH"
echo " Remove line for pmdaweblog in $PCP_PMCDCONF_PATH and re-run ./Install"
exit 2
fi
}
_defaultRegex()
{
touch $1
echo '
# Common regular expressions specifications for parsing access and error logs
# Each regular expression specification should have a name (one word),
# specify the order of regex parameters (method and size), and
# a regular expression. Regular expressions for access logs require two
# arguments to be set while errors logs require only a match.
#
# Set the online HTML Users and Administrators Guide, pmdaweblog(1) and
# regexec(3) for more details.
#
# pattern for CERN, NCSA, Netscape, Apache etc Access Logs
regex_posix CERN method,size ][ \\]+"([A-Za-z][-A-Za-z]+) [^"]*" [-0-9]+ ([-0-9]+)
# pattern for CERN, NCSA, Netscape etc Error Logs
regex_posix CERN_err - .
# pattern for Proxy Server Extended Log Format
regex_posix NS_PROXY 1,3,2,4 ][ ]+"([A-Za-z][-A-Za-z]+) [^"]*" ([-0-9]+) ([-0-9]+) ([-0-9]+)
# pattern for Squid Cache logs
regex_posix SQUID 4,3,2,1 [0-9]+\.[0-9]+[ ]+[0-9]+ [a-zA-Z0-9\.]+ ([_A-Z]+)\/([0-9]+) ([0-9]+) ([A-Z]+)
# pattern for Netscape SOCKS Server Access logs
regex_posix NS_SOCKS method,size (sockd)\[.*, ([0-9]+) bytes from .* \(http\)
# pattern for Netscape SOCKS Server Error logs
regex_posix NS_SOCKS_err - .
# pattern for FTP through a Netscape SOCKS Server Access log
regex_posix NS_FTP method,size (sockd)\[.*, ([0-9]+) bytes from .* \([0-9]+\)
# pattern for FTP through a Netscape SOCKS Server Error logs
regex_posix NS_FTP_err - .
# pattern for FTP Server access logs (normally in SYSLOG)
regex_posix SYSLOG_FTP method,size ftpd\[.*\]: ([gp][-A-Za-z]+)( )
# pattern for FTP Server error logs (normally in SYSLOG)
regex_posix SYSLOG_FTP_err - FTP LOGIN FAILED
# pattern for WU_FTP Server access logs (normally in xferlog)
regex_posix WU_FTP size,method :[0-9][0-9] [0-9]+ [0-9]+ .+ ([0-9]+) .+ [ba] .+ ([io]) [arg]
# pattern for WU_FTP Server error logs (normally in SYSLOG/messages)
regex_posix WU_FTP_err - failed login
# Server specifications. The format of each specification is
# "server" serverName on|off accessRegex accessFile errorRegex errorFile
#
# Set the online HTML Users and Administrators Guide and pmdaweblog(1)
# for more details.
#' >> $1
}
_parse_server()
{
egrep "^server" | $PCP_AWK_PROG '
{ i=index($2, ":");
if (i == 0) {
name = $2;
port = "";
}
else {
name = substr($2,1,i-1);
port = sprintf("Port %d", substr($2, i+1, length($2) - i));
}
printf("Server %s %s\n", name, port);
printf(" Access Log: %s (%s)\n", $5, $4);
printf(" Error Log: %s (%s)\n\n", $7, $6);
}'
}
_default_config ()
{
rm -f $tmp/conf
touch $tmp/conf
_defaultRegex $tmp/conf
./server.sh -q -l $tmp/conf
egrep "^server" $tmp/conf > /dev/null 2>&1
_st=$?
if [ $_st -eq 0 ]
then
./pmdaweblog -C $tmp/conf >$tmp/out 2>&1
_st=$?
if [ $_st -eq 0 ] ; then
if [ -z "$configFile" ]
then
configFile=$configDir/$iam.conf
fi
rm -f $configFile
cp $tmp/conf $configFile
args="-D $debugFlag -t $delay -n $chkDelay -S $maxserv $configFile"
socket_opt=false
fi
fi
return $_st
}
#
# --- end functions ---
if $do_pmda
then
[ ! -d $configDir ] && mkdir -p $configDir
if [ -n "$QUIET_INSTALL" ] ; then
_default_config
if [ $? -eq 0 ] ; then
pmdaInstall
exit $?
else
exit 1
fi
else
echo "----------------------------------------------------------------"
echo
echo "The default installation of the weblog PMDA will search for known"
echo "Web server configurations on this host and will setup the weblog"
echo "PMDA to monitor all associated Web server log files."
echo
echo "Otherwise, you will be prompted for the required information."
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Do you want a default weblog PMDA installation [y] ""$PCP_ECHO_C"
read ans
echo
if [ "X$ans" = X -o "X$ans" = Xy -o "X$ans" = XY ]
then
_default_config
if [ $? -eq 0 ] ; then
pmdaInstall
exit $?
else
echo
echo "Unable to find any Web servers!"
echo "Reverting to detailed installation..."
fi
fi
echo "----------------------------------------------------------------"
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Checking for a previous PMDA installation ...""$PCP_ECHO_C"
# weblogs -> weblog can be removed once all 1.0 betas are known to
# have gone away
ans=`$PCP_AWK_PROG < $PCP_PMCDCONF_PATH '
$1 == "'$iam'" {
printf "%s",$6
for (i=7;i<=NF;i++) printf " %s",$i
print ""
}'`
if [ -n "$ans" ]
then
echo " found"
_parseDefaults $ans
else
echo " appears to be a first-time install"
fi
if [ -n "$configFile" ]
then
if [ -f "$configFile" ]
then
if [ $PCP_PLATFORM = linux ] && \
egrep '^regex ' $configFile > /dev/null
then
echo "Warning: previous configuration file \"$configFile\""
echo " appears to be an incompatible version."
$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to automatically update the configuration file? [y] ""$PCP_ECHO_C"
read ans
if [ "X$ans" = X -o "$ans" = "y" -o "$ans" = "Y" ]
then
./weblogconv.sh $configFile $tmp/conf
if ./pmdaweblog -C $tmp/conf > /dev/null 2>&1
then
cp $tmp/conf $configFile
else
echo "Warning: automatic conversion failed."
echo "You can either continue, and use the default configuration file or exit"
echo "this install procedure to manually update your existing configuration."
$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to continue with the default configuration? [n] ""$PCP_ECHO_C"
read ans
if [ "$ans" = "y" -o "$ans" = "Y" ]
then
configFile=""
else
exit 1
fi
fi
fi
else
echo "Using previous configuration file \"$configFile\""
fi
else
echo "Warning: previous configuration file \"$configFile\" no longer"
echo " exists, reverting to default"
configFile=""
fi
fi
if [ "X$configFile" = X -a -f $configDir/$iam.conf ]
then
configFile=$configDir/$iam.conf
echo "Using previous configuration file \"$configFile\""
fi
if [ "X$configFile" != X ]
then
if [ -f $configFile ]
then
echo "The inital configuration file contains the following Web server details:"
echo
cat $configFile | _parse_server | ${PAGER-more}
echo
echo "------------------------------------------------------------------------------"
if ./pmdaweblog -C $configFile >$tmp/out 2>&1
then
:
else
echo "Warning: parsing this configuration file produced the following errors,"
echo " and this file will be ignored."
cat $tmp/out
echo
if [ "X$configFile" = "X$tmp/default" ]
then
echo "Arrgh ... this is the default configuration, I cannot recover from here!"
exit 1
fi
configFile=""
fi
fi
fi
echo
echo "A configuration file can be automatically generated. This can"
echo "be used to compare or replace an existing configuration file."
echo
if [ "X$configFile" = X ]
then
$PCP_ECHO_PROG $PCP_ECHO_N "Do you want a configuration file to be automatically generated [y] ""$PCP_ECHO_C"
read ans
if [ "X$ans" = X ]
then
ans="y"
fi
else
$PCP_ECHO_PROG $PCP_ECHO_N "Do you want a configuration file to be automatically generated [n] ""$PCP_ECHO_C"
read ans
if [ "X$ans" = X ]
then
ans="n"
fi
fi
if [ "X$ans" = "Xy" -o "X$ans" = "XY" ]
then
echo
echo "Now scanning for Web servers ..."
echo
if [ ! -x ./server.sh ]
then
echo "Unable to scan for Web servers as ./server.sh is missing!"
else
rm -f $tmp/conf
touch $tmp/conf
_defaultRegex $tmp/conf
./server.sh -l $tmp/conf
if egrep "^server" $tmp/conf > /dev/null 2>&1
then
echo
echo "This is a possible configuration file for your system:"
echo
cat $tmp/conf | _parse_server | ${PAGER-more}
echo
echo "------------------------------------------------------------------------------"
echo
if ./pmdaweblog -C $tmp/conf > /dev/null 2>&1
then
if [ "X$configFile" = X ]
then
$PCP_ECHO_PROG $PCP_ECHO_N "Would you like to use this configuration file [y] ""$PCP_ECHO_C"
read ans
if [ "X$ans" = "Xy" -o "X$ans" = "XY" -o "X$ans" = X ]
then
cp $tmp/conf $configDir/$iam.conf
configFile=$configDir/$iam.conf
fi
else
echo "Would you like to replace your existing configuration file with"
$PCP_ECHO_PROG $PCP_ECHO_N "the generated file [n] ""$PCP_ECHO_C"
read ans
if [ "X$ans" != "Xn" -a "X$and" != "XN" -a "X$ans" != X ]
then
cp $tmp/conf $configFile
fi
fi
else
echo "Automated configuration file generation is broken!"
if [ "X$configFile" = X ]
then
echo "Please consult the manual on how to create a configuration file."
echo "Installation failed."
exit 1
else
echo "Ignoring this file."
fi
fi
else
echo
echo "I could not find any Web servers."
fi
echo
fi
fi
echo "------------------------------------------------------------------------------"
echo
if [ "X$configFile" = X ]
then
$PCP_ECHO_PROG $PCP_ECHO_N "Do you want to specify some Web servers [n]: ""$PCP_ECHO_C"
serverAdded="false"
else
$PCP_ECHO_PROG $PCP_ECHO_N "Do you want to specify some more Web servers [n]: ""$PCP_ECHO_C"
serverAdded="true"
fi
read ans
while [ "X$ans" = "Xy" -o "X$ans" = "XY" ]
do
if [ "X$configFile" = X ]
then
if [ "X$configFile" = X -a -f $configDir/$iam.conf ]
then
echo "Replacing existing configuration file $configDir/$iam.conf"
rm -f $configDir/$iam.conf
else
echo "Creating configuration file $configDir/$iam.conf"
fi
_defaultRegex $configDir/$iam.conf
configFile="$configDir/$iam.conf"
fi
echo
serverName=`hostname`
$PCP_ECHO_PROG $PCP_ECHO_N "The name of the Web server [$serverName]: ""$PCP_ECHO_C"
read ans
if [ "X$ans" = X ]
then
serverName=`hostname`
else
serverName=$ans
fi
echo
accessPath=""
while [ "X$accessPath" = X ]
do
$PCP_ECHO_PROG $PCP_ECHO_N "The path to the access log:
""$PCP_ECHO_C"
read accessPath
if [ "X$accessPath" != X ]
then
if [ -f $accessPath ]
then
:
else
echo "$accessPath does not exist or is not a regular file"
accessPath=""
fi
fi
done
echo
errorPath=""
while [ "X$errorPath" = X ]
do
$PCP_ECHO_PROG $PCP_ECHO_N "The path to the error log:
""$PCP_ECHO_C"
read errorPath
if [ "X$errorPath" != X ]
then
if [ -f $errorPath ]
then
:
else
echo "$errorPath does not exist or is not a regular file"
errorPath=""
fi
fi
done
echo
echo "The configuration file contains these specifications:"
echo
${PAGER-more} $configFile
echo
echo "Does the configuration file contain appropriate regular expressions"
$PCP_ECHO_PROG $PCP_ECHO_N "for the \"$serverName\" Web server [y]: ""$PCP_ECHO_C"
read ans
echo
if [ "X$ans" = "Xn" -o "X$ans" = "XN" ]
then
$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to quit the installation to add new regular expressions [y]: ""$PCP_ECHO_C"
read ans
if [ "$Xans" = "Xy" -o "X$ans" = "XY" -o "X$ans" = X ]
then
echo "Edit $configFile and then rerun this Install script."
exit 1
echo
echo "Skipping $serverName ..."
fi
else
accessRegex=""
while [ "X$accessRegex" = X ]
do
if egrep "^regex_posix CERN " $configFile > /dev/null 2>&1
then
$PCP_ECHO_PROG $PCP_ECHO_N "The regex for the access log [CERN]: ""$PCP_ECHO_C"
accessRegex="CERN"
else
$PCP_ECHO_PROG $PCP_ECHO_N "The regex for the access log: ""$PCP_ECHO_C"
accessRegex=""
fi
read ans
if [ "X$ans" != X ]
then
accessRegex=$ans
fi
if [ "X$accessRegex" != X ]
then
if egrep "^regex_posix $accessRegex " $configFile > /dev/null 2>&1
then
:
else
echo "Could not find $accessRegex in $configFile"
accessRegex=""
fi
fi
done
echo
errorRegex=""
while [ "X$errorRegex" = X ]
do
if egrep "^regex_posix CERN_err " $configFile > /dev/null 2>&1
then
$PCP_ECHO_PROG $PCP_ECHO_N "The regex for the error log [CERN_err]: ""$PCP_ECHO_C"
errorRegex="CERN_err"
else
$PCP_ECHO_PROG $PCP_ECHO_N "The regex for the error log: ""$PCP_ECHO_C"
errorRegex=""
fi
read ans
if [ "X$ans" != X ]
then
errorRegex=$ans
fi
if [ "X$errorRegex" != X ]
then
if egrep "^regex_posix $errorRegex " $configFile > /dev/null 2>&1
then
:
else
echo "Could not find $errorRegex in $configFile"
errorRegex=""
fi
fi
done
echo
echo "You have specified the following Web server:"
echo
server="server $serverName on $accessRegex $accessPath $errorRegex $errorPath"
echo "$server"
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Is this correct [y]:
""$PCP_ECHO_C"
read ans
if [ "X$ans" = "Xy" -o "X$ans" = "XY" -o "X$ans" = X ]
then
echo >> $configFile
echo "# User configured server called \"$serverName\"" >> $configFile
echo $server >> $configFile
serverAdded="true"
fi
fi
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to specify another Web Server [n]: ""$PCP_ECHO_C"
read ans
echo
done
if [ "$serverAdded" = "false" ]
then
rm -f $configFile
configFile=""
fi
if [ "X$configFile" = X ]
then
echo "Please consult the manual on how to create a configuration file."
echo "Installation failed as no servers were specified."
exit 1
fi
echo
echo "You may modify the configuration file by hand and add servers"
echo "that are not currently listed, change their names, etc."
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Do you wish to exit and modify the configuration file [n] ""$PCP_ECHO_C"
read ans
if [ "X$ans" != "Xn" -a "X$ans" != "XN" -a "X$ans" != X ]
then
echo
echo "Edit $configFile and then rerun this Install script."
exit 1
fi
echo
echo "------------------------------------------------------------------------------"
echo
$PCP_ECHO_PROG $PCP_ECHO_N "The delay in seconds between forced reads of the log files [$delay] ""$PCP_ECHO_C"
read ans
if [ "X$ans" != X ]
then
delay=$ans
fi
echo
$PCP_ECHO_PROG $PCP_ECHO_N "Number of seconds of inactivity before checking for log rotation [$chkDelay] ""$PCP_ECHO_C"
read ans
if [ "X$ans" != X ]
then
chkDelay=$ans
fi
echo
$PCP_ECHO_PROG $PCP_ECHO_N "The maximum number of servers per agent process [$maxserv] ""$PCP_ECHO_C"
read ans
if [ "X$ans" != X ]
then
maxserv=$ans
fi
if [ "$do_debug" = true ]
then
echo
$PCP_ECHO_PROG $PCP_ECHO_N "the Debugging Flag (see pmdbg(1)) [$debugFlag] ""$PCP_ECHO_C"
read ans
if [ "X$ans" != X ]
then
debugFlag=$ans
fi
fi
args="-D $debugFlag -t $delay -n $chkDelay -S $maxserv $configFile"
echo
echo "------------------------------------------------------------------------------"
echo
fi
fi
pmdaInstall
exit 0
|