summaryrefslogtreecommitdiffstats
path: root/abs/core/xymon/hobbit_myth_data.py
blob: 8b38fc67c01f9330ba5602a75487a24096bf0830 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python2
# checks for the number of days of guide data left
# make sure myth_mtc ran ok


import urllib2
import string
import time , datetime
import sys,os
from MythTV import MythBE,MythDB,MythLog


BBLINE = ''
BBCOLOR="green"
DATE = time.strftime("%a %b %d %H:%M:%S %Z %Y", time.localtime(time.time()))


if os.environ['BB']:
    #print os.environ['BB']
    BB=os.environ['BB']
if os.environ['BBDISP']:
    #print os.environ['BBDISP']
    BBDISP=os.environ['BBDISP']
if os.environ['MACHINE']:
    #print os.environ['MACHINE']
    MACHINE=os.environ['MACHINE']




def check_mtc(mtc_file):
    try:
        infile = open(mtc_file, 'r')
    except(IOError), e:
        print "couldn't open %s file" %mtc_file
        return False
    else:
        mtc = infile.readlines()
        infile.close()
        for i in mtc:
            line=i
        if line.split()[0] == "Finished":
            return True
        else:
            return False

def find_data_left():
    days_left = 0
    today = datetime.datetime.today()
    try:
        be=MythBE()
        db = MythDB()
        cursor = db.cursor()
    except:
        days_left = -100
        return days_left
    try:
        cmd="select max(starttime) from program ;"
        cursor.execute(cmd)
        results=cursor.fetchall()[0][0]
        days_left = (results - today).days
    except:
        days_left = "Undetermined "
    return days_left


now = datetime.datetime.now()
date = "%s-%s-%s" %(now.year, now.month, now.day)
mtc_file = "/var/log/%s/myth_mtc.log" %date

mtc=check_mtc(mtc_file)
num_days=find_data_left()




if mtc:
    BBCOLOR="green"
    msg="\n Maintenance script ran ok \n %s \n " %mtc_file
else:
    BBCOLOR ="yellow"
    msg="\n * Maintenance script didn't run. \n %s  \n" %mtc_file

if num_days ==  1 :
    BBCOLOR="yellow"
    msg+="\n * Only 1 day of guide data left"
elif num_days == 0 :
    BBCOLOR="red "
    msg+="\n * No guide data available"

elif num_days == -100 :
    BBCOLOR="red"
    msg+="\n ** Could not connect to database!"
else:
    data_check = True
    BBCOLOR="green"
    msg+="\n %s days of guide data" %(num_days)

if os.path.isfile("/data/storage/disk0/backup/system_backups/remote_backup_failed.txt"):
    if BBCOLOR == "green":
        BBCOLOR="yellow"
    msg+="\n\n * Remote backup jobs are queued"
else:
    msg+="\n\n No remote backup jobs queued"




BBLINE=msg
LINE = "status " + MACHINE  + ".myth_mtc" + " " + BBCOLOR +  " " + DATE + " " + BBLINE
cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
os.system(cmd)

sys.exit(0)