+function check_zabbix_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
+
+
+ # Using plcsh add default, monitor user
+ plcsh <<EOF &>/dev/null
+AddPerson({'first_name' : 'Monitor', 'last_name' : 'Server', 'password' : '${PLC_MONITOR_DBPASSWORD}', 'email' : '${PLC_MONITOR_EMAIL}'})
+AddRoleToPerson('admin', '${PLC_MONITOR_EMAIL}')
+AddPersonToSite('${PLC_MONITOR_EMAIL}', '${PLC_SLICE_PREFIX}')
+UpdatePerson('${PLC_MONITOR_EMAIL}', { 'enabled' : True, 'password' : '${PLC_MONITOR_DBPASSWORD}' })
+EOF
+
+ if [ ! -f ${MONITOR_CONFIG} ] ; then
+ cat <<EOF > ${MONITOR_CONFIG}
+[monitorconfig]
+RT_DB_HOST=rt.planet-lab.org
+RT_DB_USER=
+RT_DB_PASSWORD=
+RT_DB_NAME=
+
+# RT Web user account
+RT_WEB_SERVER=https://rt.planet-lab.org/
+RT_WEB_TOOLS_PATH=
+RT_WEB_USER=
+RT_WEB_PASSWORD=
+RT_WEB_DEBUG=0
+RT_QUEUE=
+
+# PLC admin account
+API_SERVER=https://${PLC_BOOT_HOST}/PLCAPI/
+API_AUTH_USER=${PLC_MONITOR_EMAIL}
+API_AUTH_PASSWORD=${PLC_MONITOR_DBPASSWORD}
+
+# SERVER PATHS
+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}
+
+PLC_WWW_HOSTNAME=${PLC_WWW_HOST}
+
+# used for debug mode
+email=
+
+# all messages will appear to be from this address
+from_email=${PLC_MONITOR_EMAIL}
+
+# a separate address for support messages
+support_email=${PLC_MAIL_SUPPORT_ADDRESS}
+
+# mailing list copied on all out-going messages
+cc_email=
+
+[monitordatabase]
+monitor_dburi=postgres://${MONITOR_DB_USER}:${PLC_MONITOR_DBPASSWORD}@localhost:5432/${MONITOR_DB_NAME}
+zabbix_dburi=postgres://${ZABBIX_DB_USER}:${PLC_MONITOR_DBPASSWORD}@localhost:5432/${ZABBIX_DB_NAME}
+
+cachetime=60
+
+# Evaluated as true or false
+[commandline]
+cachecalls=True
+embedded=False
+
+echo=False
+debug=False
+mail=True
+bcc=False
+run=False
+checkopt=False
+squeeze=True
+policysavedb=True
+EOF