pmrep: fix archive end time reporting
[pcp.git] / qa / 1068
blob223575d6d230435307af31e31c6513790faa87c7
1 #!/bin/sh
2 # PCP QA Test No. 1068
3 # Exercise pmrep Zabbix export reporting modes.
5 # Copyright (c) 2015 Red Hat.
8 seq=`basename $0`
9 echo "QA output created by $seq"
11 . ./common.python
13 $python -c "from pcp import pmapi" >/dev/null 2>&1
14 [ $? -eq 0 ] || _notrun "python pcp pmapi module not installed"
15 $python -c "from collections import OrderedDict" >/dev/null 2>&1
16 [ $? -eq 0 ] || _notrun "python collections OrderedDict module not installed"
18 which socat >/dev/null 2>&1 || _notrun "socat binary not installed"
19 which pmrep >/dev/null 2>&1 || _notrun "pmrep not installed"
21 status=1 # failure is the default!
22 signal=$PCP_BINADM_DIR/pmsignal
23 $sudo rm -rf $tmp $tmp.* $seq.full
24 trap "cd $here; rm -rf $tmp.*; exit \$status" 0 1 2 3 15
26 _seq_store()
28 echo "--- pmrep stdout --" >>$seq.full
29 cat $tmp.pmrep.out >>$seq.full
30 echo "--- pmrep stderr --" >>$seq.full
31 cat $tmp.pmrep.err >>$seq.full
32 echo "--- socat stdout --" >>$seq.full
33 cat $tmp.socat.out >>$seq.full
34 echo "--- socat stderr --" >>$seq.full
35 cat $tmp.socat.err >>$seq.full
38 _zbx_header()
40 output=$1
42 # extract the (partially binary) header, preceding the JSON response
43 # and make it into a deterministic string
44 sed -n 1p $output | \
45 sed -e 's/{//g' | \
46 od -c | \
47 sed -n 1p | \
48 sed -e 's/ D 001.*/ D/g'
51 zabbix_port=`_find_free_port`
52 log="-z --archive $here/archives/sample-secs"
54 # real QA test starts here
55 cat <<EOF >$tmp.config
56 [options]
57 zabbix_port = $zabbix_port
58 zabbix_host = HOSTNAME
59 zabbix_server = localhost
60 [globals]
61 secs = sample.seconds
62 msecs = sample.milliseconds
63 EOF
65 cat $tmp.config >>$seq.full
67 socat tcp-listen:$zabbix_port,reuseaddr - >$tmp.socat.out 2>$tmp.socat.err &
68 pid=$!
69 sleep 2
70 pmrep -t 2 -s 3 $log -c $tmp.config -o zabbix sample >$tmp.pmrep.out 2>$tmp.pmrep.err & # will error out after socket cat dies
71 pmpid=$!
72 sleep 2
73 $signal $pid $pmpid 2>/dev/null
74 wait
75 _seq_store
77 echo "== Zabbix server input ==="
78 # check the first line has the initial ZBXD preamble (before JSON)
79 header=`_zbx_header $tmp.socat.out`
80 echo "header: $header"
81 echo "body:"
82 echo '{' # ate this from the header
83 sed -n '1!p' $tmp.socat.out
84 echo #}
86 # success, all done
87 status=0
88 exit