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
34 if [ -z "$PLC_MONITOR_IP" ] ; then
35 PLC_MONITOR_IP=$( gethostbyname $PLC_MONITOR_HOST )
38 function check_pg_hba ()
42 #### SETUP ACCESS to this user and database
43 mkdir -p $PGDATA/pg_hba.conf.d
44 CONF=$PGDATA/pg_hba.conf.d/${NAME}.conf
45 if [ ! -f $CONF ] ; then
46 echo "host $NAME $USER 127.0.0.1/32 password" > $CONF
47 echo "host $NAME $USER $PLC_MONITOR_IP/32 password" >> $CONF
49 WROTE_PG_CONFIG="true"
53 function check_user_and_db()
58 # confirm user is present or create it
59 user_present=$( psql -U postgres -c "select * from pg_user;" -d template1 | grep $USER )
60 if [ -z $user_present ] ; then
61 createuser --no-superuser --no-createdb --no-createrole --login --unencrypted --echo $USER -U postgres
65 # confirm database is present or create it
66 db_present=$( psql -U postgres -c "select * from pg_database;" -d template1 | grep $NAME )
67 if [ -z $db_present ] ; then
68 createdb --owner=$USER $NAME -U postgres
72 # Create/update the unprivileged database user and password
73 if [[ -z "$PLC_MONITOR_DBPASSWORD" || "$PLC_MONITOR_DBPASSWORD" = "None" ]] ; then
74 # Zabbix doesn't like plain uuidgen passwords
75 PLC_MONITOR_DBPASSWORD=$( uuidgen | md5sum - | awk '{print $1}' )
76 plc-config --category=plc_monitor --variable=dbpassword --value="$PLC_MONITOR_DBPASSWORD" --save=$local_config $local_config
80 if [ -n "$CREATED" ] ; then
81 psql -d template1 -U postgres -c "ALTER USER $USER WITH PASSWORD '$PLC_MONITOR_DBPASSWORD';"
84 function check_monitor_schema_and_data()
86 # NOTE: call create_all() to setup the database from the info model.
87 python -c "from monitor.database.info.model import *; from elixir import create_all; create_all()"