5 # Manage settings for the Zabbix installtion and
6 # other monitor-related things
8 # Stephen Soltesz <soltesz@cs.princeton.edu>
9 # Copyright (C) 2008 The Trustees of Princeton University
14 # Source function library and configuration
15 . /etc/plc.d/functions
16 . /etc/plc.d/monitor.functions
17 . /etc/planetlab/plc_config
18 local_config=/etc/planetlab/configs/site.xml
20 MONITORPATH=/usr/share/monitor
26 PGDATA=/var/lib/pgsql/data
27 postgresql_conf=$PGDATA/postgresql.conf
28 pghba_conf=$PGDATA/pg_hba.conf
30 # Export so that we do not have to specify -p to psql invocations
31 export PGPORT=$PLC_DB_PORT
34 MONITOR_DB_USER="monitoruser"
35 MONITOR_DB_NAME="monitor"
39 if [ -z "$PLC_MONITOR_IP" ] ; then
40 PLC_MONITOR_IP=$( gethostbyname $PLC_MONITOR_HOST )
43 function check_monitor_schema_and_data()
45 # NOTE: call create_all() to setup the database from the info model.
46 python -c "from monitor.database.info.model import *; from elixir import create_all; create_all()"
47 $MONITORPATH/init-bootman-sequence.py
50 function check_monitor_conf ()
52 MONITOR_CONFIG=/etc/monitor.conf
54 # Using plcsh add default, monitor user
55 plcsh <<EOF &>/dev/null
56 AddPerson({'first_name' : 'Monitor', 'last_name' : 'Server', 'password' : '${PLC_MONITOR_DBPASSWORD}', 'email' : '${PLC_MONITOR_EMAIL}'})
57 AddRoleToPerson('admin', '${PLC_MONITOR_EMAIL}')
58 AddPersonToSite('${PLC_MONITOR_EMAIL}', '${PLC_SLICE_PREFIX}')
59 UpdatePerson('${PLC_MONITOR_EMAIL}', { 'enabled' : True, 'password' : '${PLC_MONITOR_DBPASSWORD}' })
62 if [ ! -f ${MONITOR_CONFIG} ] ; then
63 cat <<EOF > ${MONITOR_CONFIG}
66 RT_WEB_SERVER=http://${PLC_RT_HOST}/
67 RT_WEB_TOOLS_PATH=/usr/bin/
68 RT_WEB_USER=${PLC_RT_WEB_USER}
69 RT_WEB_PASSWORD=${PLC_RT_WEB_PASSWORD}
71 RT_QUEUE=${PLC_MONITOR_RT_QUEUE}
74 API_SERVER=https://${PLC_API_HOST}:${PLC_API_PORT}/PLCAPI/
75 API_AUTH_USER=${PLC_MONITOR_EMAIL}
76 API_AUTH_PASSWORD=${PLC_MONITOR_DBPASSWORD}
79 MONITOR_SCRIPT_ROOT=${MONITORPATH}
80 MONITOR_DATA_ROOT=/var/lib/monitor
81 MONITOR_ARCHIVE_ROOT=/var/lib/monitor/archive-pdb
82 MONITOR_BOOTMANAGER_LOG=/var/www/html/monitorlog
84 MONITOR_HOSTNAME=${PLC_MONITOR_HOST}
85 MONITOR_IP=${PLC_MONITOR_IP}
87 PLC_WWW_HOSTNAME=${PLC_WWW_HOST}
91 email=${PLC_MONITOR_CC_EMAIL}
92 # all messages will appear to be from this address
93 from_email=${PLC_MONITOR_EMAIL}
94 # a separate address for support messages
95 support_email=${PLC_MAIL_SUPPORT_ADDRESS}
96 # mailing list copied on all out-going messages
97 cc_email=${PLC_MONITOR_CC_EMAIL}
99 # these are reserved values
100 RT_DB_HOST=${PLC_RT_HOST}
106 monitor_dburi=postgres://${MONITOR_DB_USER}:${PLC_MONITOR_DBPASSWORD}@localhost:5432/${MONITOR_DB_NAME}
107 zabbix_dburi=postgres://${ZABBIX_DB_USER}:${PLC_MONITOR_DBPASSWORD}@localhost:5432/${ZABBIX_DB_NAME}
111 # Evaluated as true or false
130 function create_httpd_conf ()
132 MONITOR_HTTP_CONF=/etc/httpd/conf.d/monitorweb.conf
134 if [ ! -f ${MONITOR_HTTP_CONF} ] ; then
135 # note: we need to either start this script before httpd, or always
136 # restart httpd, since there's no way to know beyond file's existence
137 # whether the values have changed or not.
138 WROTE_HTTP_CONFIG="true"
141 # TODO: support HTTPS as well as port 80. currently not specifying port
142 # 80 breaks https for other content on the myplc.
143 # TODO: make proxy port configurable.
145 cat <<EOF > ${MONITOR_HTTP_CONF}
147 # NOTE: I've tried other means of redirection, including mod_rewrite, but did
148 # not have any success. The means below is not idea, b/c it does not keep
149 # non-ssl session as non-ssl. But it works.
151 # NOTE: redirect path without trailing '/' to path with. Favor SSL.
152 Redirect /monitor https://${PLC_MONITOR_HOST}:${PLC_WWW_SSL_PORT}/monitor/
154 # NOTE: this directive strips '/monitor/' from the requested path and pastes
155 # the remaining part to the end of the ProxyPass url below. All TG urls
156 # should be relative to their current position, or the absolute path
157 # that includes /monitor/ at the beginning.
158 # TODO: make location configurable.
159 <Location '/monitor/'>
161 #Errorlog /var/log/httpd/monitorwebapp-error_log
162 #Customlog /var/log/httpd/monitorwebapp-access_log common
164 ProxyPass http://127.0.0.1:8082/
165 ProxyPassReverse http://127.0.0.1:8082/
171 function start_tg_server ()
174 pushd ${MONITORPATH}/web/MonitorWeb/
175 mkdir -p /var/log/monitor/monitorweb/
176 cp /var/log/monitorweb.log /var/lib/monitor/monitorweb/`date +%Y-%m-%d-%H-%M`-monitorweb.log
177 ./start-monitorweb.py ${MONITORPATH}/web/MonitorWeb/prod.cfg &> /var/log/monitorweb.log &
181 function stop_tg_server ()
183 pid=$( cat /var/run/monitorweb.pid )
184 if [ -n "$pid" ] ; then
189 if [ "$PLC_MONITOR_ENABLED" != "1" ] ; then
195 MESSAGE=$"Bootstrap Monitoring (please wait...)"
198 # DATABASE acces, creation, and data loading
199 check_pg_hba $MONITOR_DB_NAME $MONITOR_DB_USER
200 check_user_and_db $MONITOR_DB_NAME $MONITOR_DB_USER
201 # WRITE default /etc/monitor.conf
204 if [ -n "$WROTE_PG_CONFIG" ] ; then
205 # NOTE: restart db to enable access by users granted above.
206 service plc restart postgresql
207 service plc restart httpd
208 MESSAGE=$"Bootstrap Monitoring 2 (please wait...)"
212 check_monitor_schema_and_data
214 # create /etc/httpd/conf.d/monitorweb.conf
216 if [ -n "$WROTE_HTTP_CONFIG" ] ; then
217 # NOTE: restart web server to enable access web cfg
218 service plc restart httpd
219 MESSAGE=$"Bootstrap Monitoring 3 (please wait...)"
228 MESSAGE=$"Restarting monitor web app..."
238 MESSAGE=$"Deleting databases..."
241 dropdb -U postgres $MONITOR_DB_NAME
242 dropuser -U postgres $MONITOR_DB_USER
248 MESSAGE=$"Stopping Monitor"
252 # todo: disable cron entry?