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
39 if [ -z "$PLC_RT_IP" ] ; then
40 PLC_RT_IP=$( gethostbyname $PLC_RT_HOST )
44 # TODO: make values re-configurable... this may be an issue with RT's db, though.
45 function update_config ()
50 sed -i -e "s/$pattern/$with/g" $file
53 function check_rt_siteconfig ()
55 tmp_siteconfig=$(mktemp)
56 tmp_initialdata=$(mktemp)
58 # if the templates are newer than the actual config, then replace them.
59 if [ $MONITORPATH/rt3/RT_SiteConfig.pm -nt /etc/rt3/RT_SiteConfig.pm ] ;
62 cp -f $MONITORPATH/rt3/RT_SiteConfig.pm $tmp_siteconfig
63 cp -f $MONITORPATH/rt3/initialdata $tmp_initialdata
65 # setup RT_SiteConfig.pm
66 update_config PLC_NAME "$PLC_NAME" $tmp_siteconfig
67 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_siteconfig
69 update_config RT_DB_NAME $RT3_DB_NAME $tmp_siteconfig
70 update_config RT_DB_USER $RT3_DB_USER $tmp_siteconfig
71 update_config RT_DB_PASSWORD $PLC_MONITOR_DBPASSWORD $tmp_siteconfig
74 update_config PLC_RT_HOSTNAME $PLC_RT_HOST $tmp_initialdata
76 # copy to live configuration
77 cp -f $tmp_siteconfig /etc/rt3/RT_SiteConfig.pm
78 cp -f $tmp_initialdata /etc/rt3/initialdata
79 chmod 644 /etc/rt3/RT_SiteConfig.pm
80 chmod 644 /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
97 WROTE_PG_CONFIG="true"
102 function check_rt_aliases ()
105 if ! grep -q "rt-mailgate --queue support" /etc/aliases ;
107 sed -i -e "s/^support.*postmaster//g" /etc/aliases
108 sed -i -e "s/^security.*root//g" /etc/aliases
109 cat <<EOF >> /etc/aliases
110 # added by RT init scripts for default queues.
111 support: "|/usr/sbin/rt-mailgate --queue support --action correspond --url http://localhost/rt3/"
112 monitor: "|/usr/sbin/rt-mailgate --queue monitor --action correspond --url http://localhost/rt3/"
113 security: "|/usr/sbin/rt-mailgate --queue security --action correspond --url http://localhost/rt3/"
114 legal: "|/usr/sbin/rt-mailgate --queue legal --action correspond --url http://localhost/rt3/"
121 function check_rt_init ()
123 if [ ! -f /etc/rt3/setup.finished ] ; then
124 /usr/sbin/rt-setup-database --action init --dba postgres
125 for f in $MONITORPATH/rt3/rtinit.d/*.pl ; do
126 /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f
128 touch /etc/rt3/setup.finished
130 ###Last DB adjustments
131 #set defaultduein to 1 for support queue
132 cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
133 UPDATE queues SET defaultduein = 1 WHERE name='support'
136 #alter acl for Everyone be able to create new tickets in support list
137 #Everyone (groups.id == 3) on support (queues.id == 1 (based on order in initialdata))
138 cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
139 INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'CreateTicket','RT::Queue',1,0,0);
140 INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'ReplyToTicket','RT::Queue',1,0,0);
142 #Everyone (groups.id == 3) on monitor ( queues.id == 2 (based on order in initaldata))
143 cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
144 INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'CreateTicket','RT::Queue',2,0,0);
145 INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'ReplyToTicket','RT::Queue',2,0,0);
147 #setup custom field values
148 cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
149 INSERT INTO objectcustomfields (customfield, objectid, sortorder, creator, lastupdatedby) VALUES (1,1,1,12,12);
150 INSERT INTO customfields (name, "type", maxvalues, repeated, pattern, lookuptype, description, sortorder, creator, lastupdatedby,disabled) VALUES ('Problem Category', 'Select',1,0,'(?#Mandatory).','RT::Queue-RT::Ticket','How severe this problem is',0,12,12,0);
152 cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
153 INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Critical',0,12,12);
154 INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Major',1,12,12);
155 INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Minor',2,12,12);
156 INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Trivial',3,12,12);
158 # give permissions to users to set this field.
159 cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
160 INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'ModifyCustomField','RT::CustomField',1,0,0);
161 INSERT INTO acl (principaltype,principalid,rightname,objecttype,objectid,delegatedby,delegatedfrom) VALUES ('Group',3,'SeeCustomField','RT::CustomField',1,0,0);
169 tmp_sendmailmc=$(mktemp)
171 # if the templates is newer than the processed config, then update it
172 if grep -q "Addr=127.0.0.1," /etc/mail/sendmail.mc ;
175 cp -f /etc/mail/sendmail.mc $tmp_sendmailmc
178 update_config "Addr=127.0.0.1," "" $tmp_sendmailmc
180 # copy to live configuration
181 cp -f $tmp_sendmailmc /etc/mail/sendmail.mc
182 rm -f $tmp_sendmailmc
184 # edit /etc/mail/access to add local IP
185 if ! grep "$PLC_RT_IP" /etc/mail/access ; then
186 echo "$PLC_RT_IP RELAY" >> /etc/mail/access
187 makemap hash /etc/mail/access.db < /etc/mail/access
189 if [ ! -f /etc/smrsh/rt-mailgate ] ; then
190 ln -s /usr/sbin/rt-mailgate /etc/smrsh/rt-mailgate
192 if ! grep "$PLC_RT_HOST" /etc/mail/local-host-names ; then
193 # edit /etc/mail/local-host-names
194 echo "$PLC_RT_HOST" >> /etc/mail/local-host-names
196 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
197 service sendmail restart
203 if [ "$PLC_RT_ENABLED" != "1" ] ; then
209 MESSAGE=$"Bootstrap RT (please wait...)"
212 check_pg_hba $RT3_DB_NAME $RT3_DB_USER
213 #check_user_and_db $RT3_DB_NAME $RT3_DB_USER
216 if [ -n "$WROTE_PG_CONFIG" ] ; then
217 # NOTE: restart db to enable access by users granted above.
218 service plc restart postgresql
219 MESSAGE=$"Bootstrap RT 2 (please wait...)"
231 MESSAGE=$"Deleting databases..."
234 service plc stop httpd
236 dropdb -U postgres $RT3_DB_NAME
237 dropuser -U postgres $RT3_DB_USER
238 rm -f /etc/rt3/RT_SiteConfig.pm
239 rm -f /etc/rt3/initialdata
240 PATTERN="host all postgres 127.0.0.1/32 trust"
241 sed -i -e "s|$PATTERN||g" $PGDATA/pg_hba.conf.d/${RT3_DB_NAME}.conf
243 sed -i -e "s/.*mailgate.*//g" /etc/aliases
244 rm -f /etc/rt3/setup.finished
246 sed -i -e "s/Port=smtp, Name=MTA/Port=smtp,Addr=127.0.0.1, Name=MTA/g" /etc/mail/sendmail.mc
247 service plc start httpd
253 MESSAGE=$"Stopping RT"
256 # TODO: is there anything to stop?