pmrep: fix archive end time reporting
[pcp.git] / qa / 338
blobb3524ee26cd80ccb4d872b85c42b1695f3512859
1 #! /bin/sh
2 # PCP QA Test No. 338
3 # pmlogger_daily ... do you work at all?
5 # NEW VERSION for YYYYDDMM style naming convention (see also 530)
7 # NOTE - THIS TEST WILL FAIL IF RUN IN THE FIRST 5 MINUTES AFTER
8 # MIDNIGHT - c'est la vie, I'm afraid.
10 # Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
13 seq=`basename $0`
14 echo "QA output created by $seq"
16 # get standard environment, filters and checks
17 . ./common.product
18 . ./common.filter
19 . ./common.check
21 # This test is not stable in the vicinity of a timezone change, e.g.
22 # daylight saving or summer time transitions.
23 # Don't run if this happened in the last 2 days.
25 now_hr=`pmdate '%H'`
26 now_hr_2=`pmdate -2d '%H'`
27 if [ "$now_hr" != "$now_hr_2" ]
28 then
29 _notrun "timezone change? now = ${now_hr}H:??M, 2 days ago = ${now_hr_2}H:??M"
30 # NOTREACHED
33 _filter()
35 if fmt --help 2>&1 | grep '.-w, ' >/dev/null
36 then
37 # GNU-style fmt(1)
38 # -w, --width=WIDTH maximum line width (default of 75 columns)
39 cmd="fmt -w 76"
40 elif fmt --help 2>&1 | grep '.-w .* width' >/dev/null
41 then
42 # FreeBSD-style fmt
43 # -w <n> set maximum width to <n>
44 cmd="fmt -w 76"
45 elif fmt --help 2>&1 | grep '.-w width' >/dev/null
46 then
47 # OpenBSD-style fmt
48 # -w width
49 cmd="fmt -w 76"
50 elif fmt --help 2>&1 | grep '.-m ' >/dev/null
51 then
52 # NetBSD's version of fmt is different (may apply to other variants) ...
53 cmd="fmt -g 76 -m 77"
54 else
55 echo "Warning: no clue how to set max line length for fmt(1)"
56 cmd="fmt"
58 tee -a $seq.full \
59 | $PCP_AWK_PROG '
60 BEGIN { cmd = "'"`echo $cmd`"'" }
61 /^Archive files older than/ { eatlines=1; longone=" "; print; next }
62 eatlines { if ( match ($0, "^ ") ) {
63 for ( i=1; i <=NF; i++ ) {
64 longone = sprintf ("%s %s",longone,$i)
66 } else {
67 print longone | cmd
68 close (cmd)
69 longone = ""; eatlines = 0
70 print
72 next
74 END { if ( eatlines ) {
75 print longone | cmd
76 close (cmd)
79 { print }' \
80 | sed -f $tmp/sed \
81 | sed \
82 -e "s;$tmp;TMP;g" \
83 -e "s/`hostname`/HOST/g" \
84 -e "s/localhost/HOST/g" \
85 -e "s/local:/HOST/g" \
86 -e "s/`hostname | sed -e 's/\..*//'`/HOST/g" \
87 -e '/\/var\/adm\/pcplog\/NOTICES/d' \
88 -e 's/-rw-r--r--\./-rw-r--r--/' \
89 | $PCP_AWK_PROG '
90 /-rw-r--r--/ { print $1,"...",$5,"...",$9; next }
91 { print }' \
92 | _filter_cron_scripts
95 _cleanup()
97 cd $here
98 $sudo rm -f $tmp.*
99 $sudo rm -rf $tmp
100 $sudo mv $PCP_LOG_DIR/NOTICES.$$ $PCP_LOG_DIR/NOTICES
103 status=1 # failure is the default!
104 trap "_cleanup; exit \$status" 0 1 2 3 15
105 $sudo rm -rf $tmp $tmp.*
107 # take explicit control of the umask
108 umask 022
110 $sudo mv $PCP_LOG_DIR/NOTICES $PCP_LOG_DIR/NOTICES.$$
111 rm -f $seq.full
112 mkdir $tmp
114 # real QA test starts here
115 unset verbose
116 for loop in 1 2
118 echo >$tmp/sed
119 for day in 0 1 2 3 4 5
121 fmt=%Y%m%d
122 # aiming for the time to be 00:02 and 00:04 on each day,
123 # even if that is ahead of NOW for today
125 now_hr=`pmdate %H`
126 hour=-$now_hr
127 now_min=`pmdate %M`
128 min2=`expr 2 - $now_min`
129 [ "$min2" -ge 0 ] && min2="+$min2"
130 min4=`expr 4 - $now_min`
131 [ "$min4" -ge 0 ] && min4="+$min4"
132 namea=`pmdate -${day}d ${hour}H ${min2}M $fmt.%H.%M`
133 nameb=`pmdate -${day}d ${hour}H ${min4}M $fmt.%H.%M`
134 yesterday=`pmdate -1d ${hour}H ${min2}M $fmt`
135 stampa=`echo $namea | sed -e 's/\.//g'`
136 stampb=`echo $nameb | sed -e 's/\.//g'`
137 echo "s/$namea/NOW-$day.00.02/g" >>$tmp/sed
138 echo "s/$nameb/NOW-$day.00.04/g" >>$tmp/sed
140 for ext in 0 index meta
142 cp archives/arch_a.$ext $tmp/$namea.$ext
143 touch -t $stampa $tmp/$namea.$ext
144 cp archives/arch_b.$ext $tmp/$nameb.$ext
145 touch -t $stampb $tmp/$nameb.$ext
146 done
147 done
148 echo "s/NOW-0/TODAY/g" >>$tmp/sed
149 echo "s/NOW-1/YESTERDAY/g" >>$tmp/sed
150 echo "s/`pmdate %Y%m%d`/TODAY/g" >>$tmp/sed
151 echo "s/$yesterday/YESTERDAY/g" >>$tmp/sed
153 echo >$tmp/control '$version=1.1
154 LOCALHOSTNAME n n '"$tmp"' ./config'
156 cat $tmp/sed >>$seq.full
157 echo >>$seq.full
159 echo
160 echo "=== [${verbose+verbose}] regular show ==="
161 echo "=== [${verbose+verbose}] regular show ===" >>$seq.full
162 $sudo $PCP_BINADM_DIR/pmlogger_daily -o -c $tmp/control -k 3 $verbose -l $tmp.log
164 $sudo cat $tmp.log | _filter
165 ls -lt $tmp >>$seq.full
166 ls $tmp | sed -f $tmp/sed | tee -a $seq.full | LC_COLLATE=POSIX sort
168 echo
169 echo "=== [${verbose+verbose}] nothing to do but cull some more ==="
170 echo "=== [${verbose+verbose}] nothing to do but cull some more ===" >>$seq.full
171 for ext in 0 index meta
173 mv $tmp/$yesterday.$ext $tmp/save.$ext
174 done
175 $sudo $PCP_BINADM_DIR/pmlogger_daily -o -c $tmp/control -k 2 $verbose -l $tmp.log
176 $sudo cat $tmp.log | _filter
177 ls -lt $tmp >>$seq.full
178 ls $tmp | sed -f $tmp/sed | tee -a $seq.full | LC_COLLATE=POSIX sort
180 echo
181 echo "=== [${verbose+verbose}] error, output already exists ==="
182 echo "=== [${verbose+verbose}] error, output already exists ===" >>$seq.full
183 for ext in 0 index meta
185 cp archives/arch_a.$ext $tmp/$yesterday.17.18.$ext
186 mv $tmp/save.$ext $tmp/$yesterday.$ext
187 done
188 $sudo $PCP_BINADM_DIR/pmlogger_daily -o -c $tmp/control -k 2 $verbose -l $tmp.log
189 $sudo cat $tmp.log | _filter
190 ls -lt $tmp >>$seq.full
191 ls $tmp | sed -f $tmp/sed | tee -a $seq.full | LC_COLLATE=POSIX sort
193 verbose=-V
194 rm -f $tmp/*
195 done
197 # all done
198 status=0
199 exit