blob: 1987a270583813b06f611e2052e433194837f20a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
from django.core.management.base import BaseCommand, CommandError
from sbhs_server import settings
from sbhs_server.tables.models import Board
from sbhs_server import helpers
class Command(BaseCommand):
args = ''
help = 'Initializes the SBHS board data in the database'
def handle(self, *args, **options):
previous_onlines = Board.objects.only("mid").filter(online=True)
previous_onlines = [p.mid for p in previous_onlines]
for o in settings.online_mids:
try:
Board.objects.get_or_create(mid=o)
except:
pass
new_offlines = []
for p in previous_onlines:
if p not in settings.online_mids:
new_offlines.append(p)
message = "SBHS Administrator,\n\n"
message += "Following issue requires immidiate attention.\n\n"
message += "SBHS could not be connected\n"
for n in new_offlines:
message += ("MID: %d\n" % n)
message += "\nYou can check the SBHS status on http://vlabs.iitb.ac.in/sbhs/admin/."
message += " Possible correction actions are:\n"
message += "1. Run this command without brackets -> ( cd $SBHS_SERVER_ROOT; ./cron_job.sh )\n"
message += "2. If same machine comes offline multiple times, replacement of the machine is advised.\n\n\n"
message += "Regards,\nSBHS Vlabs Server Code"
print "New offline board mids", new_offlines
subject = "SBHS Vlabs: Notice - SBHS not connected"
if len(new_offlines) > 0:
for admin in settings.SBHS_ADMINS:
helpers.mailer.email(admin[2], subject, message)
Board.objects.filter(mid__in=settings.online_mids).update(online=True)
Board.objects.exclude(mid__in=settings.online_mids).update(online=False)
self.stdout.write('Boards loaded')
|