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/planetlab/plc_config
17 local_config=/etc/planetlab/configs/site.xml
19 MONITORPATH=/usr/share/monitor
25 PGDATA=/var/lib/pgsql/data
26 postgresql_conf=$PGDATA/postgresql.conf
27 pghba_conf=$PGDATA/pg_hba.conf
29 # Export so that we do not have to specify -p to psql invocations
30 export PGPORT=$PLC_DB_PORT
38 if [ -z "$PLC_MONITOR_IP" ] ; then
39 PLC_MONITOR_IP=$( gethostbyname $PLC_MONITOR_HOST )
42 if [ "$PLC_MONITOR_ENABLED" != "1" ] ; then
46 # TODO: make values re-configurable... this may be an issue with RT's db, though.
47 function update_config ()
52 sed -i -e "s/$pattern/$with/g" $file
55 function check_rt_siteconfig ()
57 tmp_siteconfig=$(mktemp)
58 tmp_initialdata=$(mktemp)
60 # if the templates are newer than the actual config, then replace them.
61 if [ $MONITORPATH/rt3/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ;
64 cp -f $MONITORPATH/rt3/RT_SiteConfig.pm $tmp_siteconfig
65 cp -f $MONITORPATH/rt3/initialdata $tmp_initialdata
67 # setup RT_SiteConfig.pm
68 update_config PLC_NAME $PLC_NAME $tmp_siteconfig
69 update_config PLC_RT_HOSTNAME $PLC_RT_HOSTNAME $tmp_siteconfig
71 update_config RT_DB_NAME $RT3_DB_NAME $tmp_siteconfig
72 update_config RT_DB_USER $RT3_DB_USER $tmp_siteconfig
73 update_config RT_DB_PASSWORD $PLC_MONITOR_DBPASSWORD $tmp_siteconfig
76 update_config PLC_RT_HOSTNAME $PLC_RT_HOSTNAME $tmp_initialdata
78 # copy to live configuration
79 cp -f $tmp_siteconfig /etc/rt3/RT_SiteConfig.pm
80 cp -f $tmp_initialdata /etc/rt3/initialdata
83 rm -f $tmp_initialdata
87 function check_rt_pghba ()
91 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
92 PATTERN="host all postgres 127.0.0.1/32 trust"
94 if ! grep -q $PATTERN $CONF ; then
95 #### SETUP ACCESS from postgres user to run init for the first time.
96 echo $PATTERN >> $CONF
101 function check_rt_aliases ()
104 if ! grep -q "rt-mailgate --queue support" /etc/aliases ;
106 cat <<EOF >> /etc/aliases
108 # added by RT init scripts for default queues.
109 support: "|/usr/sbin/rt-mailgate --queue support --action correspond --url http://localhost/rt3/"
110 monitor: "|/usr/sbin/rt-mailgate --queue monitor --action correspond --url http://localhost/rt3/"
111 security: "|/usr/sbin/rt-mailgate --queue security --action correspond --url http://localhost/rt3/"
112 legal: "|/usr/sbin/rt-mailgate --queue legal --action correspond --url http://localhost/rt3/"
119 function check_rt_init ()
121 if [ ! -f /etc/rt3/setup.finished ] ; then
122 /usr/sbin/rt-setup-database --action init --dba postgres
123 touch /etc/rt3/setup.finished
126 ###Last DB adjustments
127 #disable queue General, set disabled to 0 in table queues, set defaultduein to 1 for support queue
128 # /bin/su - -c "/bin/echo \"UPDATE queues SET disabled = 1 WHERE name='General';\"|/usr/bin/psql -U postgres -d rt" postgres
129 # /bin/su - -c "/bin/echo \"UPDATE queues SET defaultduein = 1 WHERE name='support';\"|/usr/bin/psql -U postgres -d rt" postgres
131 #alter acl for Everyone be able to create new tickets in support list
132 #Everyone (installation id 3) on support ( installation is 3)
133 # /bin/su - -c "/bin/echo \"INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'CreateTicket','RT::Queue',3,0,0);\"|/usr/bin/psql -U postgres -d rt" postgres
134 # /bin/su - -c "/bin/echo \"INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'ReplyToTicket','RT::Queue',3,0,0);\"|/usr/bin/psql -U postgres -d rt" postgres
135 # #Everyone (installation id 3) on monitor ( installation is 2)
136 # /bin/su - -c "/bin/echo \"INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'CreateTicket','RT::Queue',2,0,0);\"|/usr/bin/psql -U postgres -d rt" postgres
137 # /bin/su - -c "/bin/echo \"INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'ReplyToTicket','RT::Queue',2,0,0);\"|/usr/bin/psql -U postgres -d rt" postgres
143 MESSAGE=$"Bootstrap RT (please wait...)"
146 check_pg_hba $RT3_DB_NAME $RT3_DB_USER
147 check_user_and_db $RT3_DB_NAME $RT3_DB_USER
150 if [ -n "$WROTE_PG_CONFIG" ] ; then
151 # NOTE: restart db to enable access by users granted above.
152 service plc restart postgresql
153 MESSAGE=$"Bootstrap RT 2 (please wait...)"
164 MESSAGE=$"Deleting databases..."
167 dropdb -U postgres $RT3_DB_NAME
168 dropuser -U postgres $RT3_DB_USER
169 rm -f /etc/rt3/RT_SiteConfig.pm
170 rm -f /etc/rt3/initialdata
171 PATTERN="host all postgres 127.0.0.1/32 trust"
172 sed -i -e "s/$PATTERN//g" $PGDATA/pg_hba.conf.d/${RT3_DB_USER}.conf
174 sed -i -e "s/.*mailgate.*//g" /etc/aliases
180 MESSAGE=$"Stopping Monitor"
183 # TODO: is there anything to stop?