X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor-server.init;h=f8e5a0228a5eddc3b131df6dd23698aef8dc83dd;hb=7b3d462aa05fcc1892fd914db163143f36a05945;hp=df007518799adbb8c7e4d199ff8d53c7f1270179;hpb=170be1fae6fd5956641668443245c50fbf7fd566;p=monitor.git diff --git a/monitor-server.init b/monitor-server.init index df00751..f8e5a02 100644 --- a/monitor-server.init +++ b/monitor-server.init @@ -16,7 +16,7 @@ . /etc/planetlab/plc_config local_config=/etc/planetlab/configs/site.xml -MONITORPATH=/usr/share/monitor-server +MONITORPATH=/usr/share/monitor # Be verbose set -x @@ -97,6 +97,46 @@ function check_schema_and_data() fi } +function check_templates_and_import () +{ + # LOG IN + COOKIE_FILE=/tmp/cookiejar.txt + rm -f ${COOKIE_FILE} + TEMPLATES_DIR=${MONITORPATH}/zabbix/templates + curl -s --cookie $COOKIE_FILE --cookie-jar $COOKIE_FILE \ + --form "enter=Enter" \ + --form "name=Admin" \ + --form "password=zabbix" \ + "http://${PLC_MONITOR_HOST}/zabbix/index.php?login=1" + + deleted=$( grep 'deleted' $COOKIE_FILE ) + if [ -n "$deleted" ] ; then + echo "Login to the zabbix web server failed!!!" + return 1 + fi + + for file in ${TEMPLATES_DIR}/*.xml ; do + # 0 - update , 1 - skip, 0 - add + echo "############### IMPORTING $file" >> /var/log/monitor.log + curl -s --cookie $COOKIE_FILE --cookie-jar $COOKIE_FILE \ + --form "config=1" \ + --form "import_file=@${file}" \ + --form "rules[host][exist]=0" \ + --form "rules[host][missed]=0" \ + --form "rules[template][exist]=0" \ + --form "rules[template][missed]=1" \ + --form "rules[item][exist]=0" \ + --form "rules[item][missed]=0" \ + --form "rules[trigger][exist]=0" \ + --form "rules[trigger][missed]=0" \ + --form "rules[graph][exist]=0" \ + --form "rules[graph][missed]=0" \ + --form "import=Import" \ + "http://${PLC_MONITOR_HOST}/zabbix/exp_imp.php" >> /var/log/monitor.log + done +} + + function check_monitor_conf () { MONITOR_CONFIG=/etc/monitor.conf @@ -135,9 +175,9 @@ API_AUTH_USER=${PLC_MONITOR_EMAIL} API_AUTH_PASSWORD=${PLC_MONITOR_DBPASSWORD} # SERVER PATHS -MONITOR_SCRIPT_ROOT=/usr/share/monitor-server -MONITOR_DATA_ROOT=/var/lib/monitor-server -MONITOR_ARCHIVE_ROOT=/var/lib/monitor-server/archive-pdb +MONITOR_SCRIPT_ROOT=${MONITORPATH} +MONITOR_DATA_ROOT=/var/lib/monitor +MONITOR_ARCHIVE_ROOT=/var/lib/monitor/archive-pdb MONITOR_HOSTNAME=${PLC_MONITOR_HOST} MONITOR_IP=${PLC_MONITOR_IP} @@ -239,11 +279,11 @@ case "$1" in MESSAGE=$"Bootstrap Monitoring" dialog "$MESSAGE" - # DATABASE acces, creation, and data loading check_pg_hba check_user_and_db check_schema_and_data + check_templates_and_import # WRITE default /etc/monitor.conf check_monitor_conf @@ -261,7 +301,14 @@ case "$1" in MESSAGE=$"Syncing PLC db with Zabbix DB" dialog "$MESSAGE" + # turn off zabbix server, etc. before writing to the db. + service plc stop monitor + $MONITORPATH/zabbix/zabbixsync.py --setupglobal &> /var/log/monitor-server + # import any templates + check_templates_and_import + + service plc start monitor result "$MESSAGE" ;;