run certain scripts periodically
authorStephen Soltesz <soltesz@cs.princeton.edu>
Mon, 22 Jun 2009 19:51:09 +0000 (19:51 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Mon, 22 Jun 2009 19:51:09 +0000 (19:51 +0000)
run certain scripts at startup
use plcquery instead of getusersfromplc
give 'priv' argument to adduserstort.pl

rt3/adduserstort.pl
rt3/getusersfromplc.py [deleted file]
rt3/monitor-rt3.init
rt3/rt.cron [moved from rt3/syncrtusers.cron with 100% similarity]
rt3/rtcron.d/syncadmins.sh [new file with mode: 0644]
rt3/rtcron.d/syncusers.sh [new file with mode: 0644]
rt3/rtcron.sh [new file with mode: 0755]

index 899e4ce..91ff801 100644 (file)
@@ -25,8 +25,13 @@ my $organization = '';
 my $address1 = '';
 my $city = '';
 my $country = '';
+my $priv = 0;
 
-print $ARGV[0];
+if ( $ARGV[0] == 'priv' )
+{
+   shift @ARGV;
+   $priv = 1;
+}
 
 open(USERS_DATA, $ARGV[0]) || die("Could not open file!");
 @raw_data=<USERS_DATA>;
@@ -42,8 +47,8 @@ foreach $bc_user (@raw_data)
              RealName => $realname,
              EmailAddress => $email_address,
              Password => 'Passw0rd',
-             Organization => $organization,
-             Privileged => 0);
+                        Organization => $organization,
+             Privileged => $priv);
              #Address1 => $address1,
              #City => $city,
              #Country => country,
diff --git a/rt3/getusersfromplc.py b/rt3/getusersfromplc.py
deleted file mode 100755 (executable)
index da2c959..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/python
-
-from monitor.wrapper import plc
-
-api = plc.api
-
-sites = api.GetSites({'login_base' : 'princeton'}, ['person_ids', 'name'])
-for s in sites:
-       persons = api.GetPersons(sites[0]['person_ids'], ['email' , 'first_name', 'last_name',])
-       for p in persons:
-               print "%s,%s %s,%s" % (p['email'], p['first_name'], p['last_name'], s['name'])
index ca94353..15c85cd 100644 (file)
@@ -122,24 +122,18 @@ function check_rt_init ()
 {
        if [ ! -f /etc/rt3/setup.finished ] ; then
                /usr/sbin/rt-setup-database --action init --dba postgres
-               for f in $MONITORPATH/rt3/rtinit.d/*.pl ; do 
+               for f in $MONITORPATH/rt3/rtconf.d/*.pl ; do 
                        /usr/sbin/rt-setup-database --action insert --dba postgres --datafile $f
                done
-               touch /etc/rt3/setup.finished
 
-       ###Last DB adjustments
-       #setup custom field values
-       cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
-INSERT INTO objectcustomfields (customfield, objectid, sortorder, creator, lastupdatedby) VALUES (1,1,1,12,12);
-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);
-EOF
-       cat <<EOF | /usr/bin/psql -U postgres -d $RT3_DB_NAME
-INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Critical',0,12,12);
-INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Major',1,12,12);
-INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Minor',2,12,12);
-INSERT INTO customfieldvalues (customfield, name, sortorder, creator, lastupdatedby) VALUES (1,'Trivial',3,12,12);
-EOF
+               # run initial setup scripts (run only once, or for the first time)
+               for f in $MONITORPATH/rt3/rtsetup.d/*.{pl,py,sh} ; do 
+                       $f
+               done
 
+               touch /etc/rt3/setup.finished
+
+       fi
 }
 
 check_rt_sendmail ()
similarity index 100%
rename from rt3/syncrtusers.cron
rename to rt3/rt.cron
diff --git a/rt3/rtcron.d/syncadmins.sh b/rt3/rtcron.d/syncadmins.sh
new file mode 100644 (file)
index 0000000..8009a18
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+echo "syncadmins.sh"
+MDIR=/usr/share/monitor
+source $MDIR/monitorconfig.sh
+${MONITOR_SCRIPT_ROOT}/plcquery.py --type person --withsitename --byrole admin \
+                                       --format="%(email)s,%(first_name)s %(last_name)s,%(name)s" \
+                               | ${MONITOR_SCRIPT_ROOT}/rt3/adduserstort.pl priv -
diff --git a/rt3/rtcron.d/syncusers.sh b/rt3/rtcron.d/syncusers.sh
new file mode 100644 (file)
index 0000000..9e53f6c
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+MDIR=/usr/share/monitor
+source $MDIR/monitorconfig.sh
+${MONITOR_SCRIPT_ROOT}/plcquery.py --type person --withsitename --byrole pi \
+                                       --format="%(email)s,%(first_name)s %(last_name)s,%(name)s" \
+                               | ${MONITOR_SCRIPT_ROOT}/rt3/adduserstort.pl -
diff --git a/rt3/rtcron.sh b/rt3/rtcron.sh
new file mode 100755 (executable)
index 0000000..e14b533
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+D=/usr/share/monitor/
+for f in $D/rt3/rtcron.d/*.sh ; do
+       bash -c "$f"
+done