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
21 WEB_ROOT_PATH=web/MonitorWeb/monitorweb
22 WEB_XML_PATH=static/xml
28 PGDATA=/var/lib/pgsql/data
29 postgresql_conf=$PGDATA/postgresql.conf
30 pghba_conf=$PGDATA/pg_hba.conf
32 # Export so that we do not have to specify -p to psql invocations
33 export PGPORT=$PLC_DB_PORT
36 MONITOR_DB_USER=$PLC_MONITOR_DBUSER
37 MONITOR_DB_NAME=$PLC_MONITOR_DBNAME
41 if [ -z "$PLC_MONITOR_IP" ] ; then
42 PLC_MONITOR_IP=$( gethostbyname $PLC_MONITOR_HOST )
45 function update_config ()
50 sed -i -e "s/$pattern/$with/g" $file
52 function apply_template ()
58 cp $TEMPLATE $tmp_file
60 update_config PLC_NAME "$PLC_NAME" $tmp_file
61 update_config PLC_WWW_HOSTNAME $PLC_WWW_HOST $tmp_file
62 update_config MONITOR_HOSTNAME $PLC_MONITOR_HOST $tmp_file
64 cp $tmp_file $DESTFILE
68 function check_gadget_config ()
70 for input_file in $MONITORPATH/$WEB_ROOT_PATH/$WEB_XML_PATH/*.in ; do
71 output_file=$MONITORPATH/$WEB_ROOT_PATH/$WEB_XML_PATH/`basename $input_file | sed -e 's/.in\$//'`
72 if [ $input_file -nt $output_file ] ; then
73 apply_template $input_file $output_file
78 function check_monitor_schema_and_data_init()
80 # from monitor.functions
81 check_monitor_schema_and_data
83 $MONITORPATH/config.d/init-bootman-sequence.py
86 function check_monitor_conf ()
88 MONITOR_CONFIG=/etc/monitor.conf
90 # Using plcsh add default, monitor user
91 plcsh <<EOF &>/dev/null
92 AddPerson({'first_name' : 'Monitor', 'last_name' : 'Server', 'password' : '${PLC_MONITOR_DBPASSWORD}', 'email' : '${PLC_MONITOR_EMAIL}'})
93 AddRoleToPerson('admin', '${PLC_MONITOR_EMAIL}')
94 AddPersonToSite('${PLC_MONITOR_EMAIL}', '${PLC_SLICE_PREFIX}')
95 UpdatePerson('${PLC_MONITOR_EMAIL}', { 'enabled' : True, 'password' : '${PLC_MONITOR_DBPASSWORD}' })
98 if [ ! -f ${MONITOR_CONFIG} ] ; then
99 cat <<EOF > ${MONITOR_CONFIG}
101 # RT Web user account
102 RT_WEB_SERVER=http://${PLC_RT_HOST}/
103 RT_WEB_TOOLS_PATH=/usr/bin/
104 RT_WEB_USER=${PLC_RT_WEB_USER}
105 RT_WEB_PASSWORD=${PLC_RT_WEB_PASSWORD}
107 RT_QUEUE=${PLC_MONITOR_RT_QUEUE}
110 API_SERVER=https://${PLC_API_HOST}:${PLC_API_PORT}/PLCAPI/
111 API_AUTH_USER=${PLC_MONITOR_EMAIL}
112 API_AUTH_PASSWORD=${PLC_MONITOR_DBPASSWORD}
115 MONITOR_SCRIPT_ROOT=${MONITORPATH}
116 MONITOR_DATA_ROOT=/var/lib/monitor
117 MONITOR_ARCHIVE_ROOT=/var/lib/monitor/archive-pdb
118 MONITOR_BOOTMANAGER_LOG=/var/www/html/monitorlog
120 MONITOR_HOSTNAME=${PLC_MONITOR_HOST}
121 MONITOR_IP=${PLC_MONITOR_IP}
123 PLC_WWW_HOSTNAME=${PLC_WWW_HOST}
126 email=${PLC_MONITOR_EMAIL}
127 # all messages will appear to be from this address
128 from_email=${PLC_MONITOR_EMAIL}
129 # a separate address for support messages
130 support_email=${PLC_MAIL_SUPPORT_ADDRESS}
131 # mailing list copied on all out-going messages
132 cc_email=${PLC_MONITOR_CC_EMAIL}
133 exception_email=${PLC_MONITOR_CC_EMAIL}
135 # these are reserved values
136 RT_DB_HOST=${PLC_RT_HOST}
142 monitor_dburi=postgres://${MONITOR_DB_USER}:${PLC_MONITOR_DBPASSWORD}@${PLC_MONITOR_DBHOST}:5432/${MONITOR_DB_NAME}
146 # Evaluated as true or false
165 function create_httpd_conf ()
167 MONITOR_HTTP_CONF=/etc/httpd/conf.d/monitorweb.conf
169 if [ ! -f ${MONITOR_HTTP_CONF} ] ; then
170 # note: we need to either start this script before httpd, or always
171 # restart httpd, since there's no way to know beyond file's existence
172 # whether the values have changed or not.
173 WROTE_HTTP_CONFIG="true"
176 # TODO: support HTTPS as well as port 80. currently not specifying port
177 # 80 breaks https for other content on the myplc.
178 # TODO: make proxy port configurable.
180 cat <<EOF > ${MONITOR_HTTP_CONF}
182 # NOTE: I've tried other means of redirection, including mod_rewrite, but did
183 # not have any success. The means below is not idea, b/c it does not keep
184 # non-ssl session as non-ssl. But it works.
186 # NOTE: redirect path without trailing '/' to path with. Favor SSL.
187 Redirect /monitor https://${PLC_MONITOR_HOST}:${PLC_WWW_SSL_PORT}/monitor/
188 #RedirectMatch ^/$ https://${PLC_MONITOR_HOST}:${PLC_WWW_SSL_PORT}/monitor
190 # NOTE: this directive strips '/monitor/' from the requested path and pastes
191 # the remaining part to the end of the ProxyPass url below. All TG urls
192 # should be relative to their current position, or the absolute path
193 # that includes /monitor/ at the beginning.
194 # TODO: make location configurable.
195 <Location '/monitor/'>
197 #Errorlog /var/log/httpd/monitorwebapp-error_log
198 #Customlog /var/log/httpd/monitorwebapp-access_log common
200 ProxyPass http://127.0.0.1:8082/
201 ProxyPassReverse http://127.0.0.1:8082/
207 function start_tg_server ()
210 pushd ${MONITORPATH}/web/MonitorWeb/
211 mkdir -p /var/lib/monitor/monitorweb/
212 cp /var/log/monitorweb.log /var/lib/monitor/monitorweb/`date +%Y-%m-%d-%H-%M`-monitorweb.log
213 ./start-monitorweb.py ${MONITORPATH}/web/MonitorWeb/prod.cfg &> /var/log/monitorweb.log &
217 function stop_tg_server ()
219 pid=$( cat /var/run/monitorweb.pid )
220 if [ -n "$pid" ] ; then
225 if [ "$PLC_MONITOR_ENABLED" != "1" ] ; then
231 MESSAGE=$"Bootstrap Monitoring (please wait...)"
234 # DATABASE acces, creation, and data loading
235 check_pg_hba $MONITOR_DB_NAME $MONITOR_DB_USER
236 check_user_and_db $MONITOR_DB_NAME $MONITOR_DB_USER
237 # WRITE default /etc/monitor.conf
242 if [ -n "$WROTE_PG_CONFIG" ] ; then
243 # NOTE: restart db to enable access by users granted above.
244 service plc restart postgresql
245 service plc restart httpd
246 MESSAGE=$"Bootstrap Monitoring 2 (please wait...)"
250 check_monitor_schema_and_data_init
252 # create /etc/httpd/conf.d/monitorweb.conf
254 if [ -n "$WROTE_HTTP_CONFIG" ] ; then
255 # NOTE: restart web server to enable access web cfg
256 service plc restart httpd
257 MESSAGE=$"Bootstrap Monitoring 3 (please wait...)"
266 MESSAGE=$"Restarting monitor web app..."
276 MESSAGE=$"Deleting databases..."
279 dropdb -U postgres $MONITOR_DB_NAME
280 dropuser -U postgres $MONITOR_DB_USER
286 MESSAGE=$"Stopping Monitor"
290 # todo: disable cron entry?