Various updates; Add logAxis patch for graphite; Add namespaces to summary scripts.
[myops.git] / web / collect / client / collect.sh
1 #!/bin/bash 
2
3 if [ -f /etc/planetlab/plc_config ]; then
4         source /etc/planetlab/plc_config
5 else
6         PLC_SLICE_PREFIX='pl'
7 fi
8 LOGFILE=/home/${PLC_SLICE_PREFIX}_myops/myops.log
9
10 cd /home/${PLC_SLICE_PREFIX}_myops
11
12 if [ -f /usr/boot/myops_cacert.pem ] ; then
13         CURL_ARGS="$CURL_ARGS --cacert /usr/boot/myops_cacert.pem"
14 else
15         CURL_ARGS="$CURL_ARGS --insecure"
16 fi
17
18 # TODO: add a timeout to eval, that kills children after X seconds
19 function write_key_command ()
20 {
21     key=$1
22     command=$2
23     value=`eval $command`
24     write_key_value "$key" "$value"
25 }
26 function write_key_value ()
27 {
28     key=$1
29     value=$2
30     (
31         flock -x -w 240 200 2> /dev/null
32         echo $key : $value >> $LOGFILE
33     ) 200>/var/lock/myops
34 }
35
36 rm -f $LOGFILE
37 count=0
38
39 while read key colon command ; do
40         if [[ $colon = ":" ]] ; then
41                 write_key_command "$key" "$command" &
42                 count=$(( $count + 1 ))
43         else
44                 if [[ $colon = ":=" ]] ; then
45                         eval $key=`eval $command`
46                 else if [[ $colon = "()" ]] ; then
47                         eval "function $key () $command"
48                      fi
49                 fi
50         fi
51 done < <( curl $CURL_ARGS -s https://IPADDR/PlanetLabConf/input.cfg )
52
53 write_key_value "count" "$count"
54
55