diff options
Diffstat (limited to 'abs/core/LinHES-system')
| -rwxr-xr-x | abs/core/LinHES-system/PKGBUILD | 14 | ||||
| -rw-r--r-- | abs/core/LinHES-system/msg.cfg | 23 | ||||
| -rw-r--r-- | abs/core/LinHES-system/myth_status.py | 302 |
3 files changed, 252 insertions, 87 deletions
diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD index f7e3a55..0a0d5f1 100755 --- a/abs/core/LinHES-system/PKGBUILD +++ b/abs/core/LinHES-system/PKGBUILD @@ -1,6 +1,6 @@ pkgname=LinHES-system pkgver=8.1 -pkgrel=3 +pkgrel=4 arch=('i686' 'x86_64') install=system.install pkgdesc="Everything that makes LinHES an automated system" @@ -30,7 +30,7 @@ binfiles="LinHES-start optimize_mythdb.py myth_mtc.py myth_mtc.sh source=(LinHES-session LinHES-profile.sh $binfiles alsa-base diskspace.cron cacheclean.cron xfs_defrag.cron readme_is_xml readme_light add_storage.readme - system-sudo.rules ) + system-sudo.rules msg.cfg) package() { cd $srcdir @@ -70,6 +70,9 @@ package() { chown -R root:root $pkgdir/etc/sudoers.d install -o root -g root -m 0750 $srcdir/system-sudo.rules $pkgdir/etc/sudoers.d/system_sudo + #config file of msg_daemon + install -m755 -D $srcdir/msg.cfg $pkgdir/usr/MythVantage/etc/msg.cfg + } md5sums=('95720bd676d0b05e89e1f6ae6e0b4e2d' @@ -83,7 +86,7 @@ md5sums=('95720bd676d0b05e89e1f6ae6e0b4e2d' '542e670e78d117657f93141e9689f54d' '8da6a7f1703a002f84e66629e847d8a6' 'bb72ab230c7a71706285bd0f31a4fb1f' - 'a8c79014423a95b41908fbe74ba83a6e' + '07fc64580cc98aa28561730ac7695eca' '962a3e9eaba2d1466251b7ab0956705d' '1758aed160de64abfafb28a3a8f3390e' '33fbebbd546672cedd3c5e7350ab414e' @@ -117,7 +120,7 @@ md5sums=('95720bd676d0b05e89e1f6ae6e0b4e2d' '34fc1f58ad1eabf4eff4979d420760c0' 'c3ada01d3a739abe3f920b02d4ea3f6e' 'a94fe6d980f4b810f2e2ae5352084b39' - '1c71ff372978159f09342b18954500b3' + 'f808e8614246913a7f633b51c7169c85' '3fc3d584fadd47f82c5cfe8ac0f4322a' '503df99218373dfc75e7e7f5e449a44e' '4a1fda884dcd7d65fb2690fbdbd92a83' @@ -132,4 +135,5 @@ md5sums=('95720bd676d0b05e89e1f6ae6e0b4e2d' '36bdfa8d877cea20ca3870faf08e08d5' '59d0602bac7e06f11abba1894acc8bb0' 'da432d68962e109e09beb2b71c8c8571' - '366ccb097d1c221389709485c3b2d159') + '366ccb097d1c221389709485c3b2d159' + 'bdd37627c9effd745a051fd2d279975b') diff --git a/abs/core/LinHES-system/msg.cfg b/abs/core/LinHES-system/msg.cfg new file mode 100644 index 0000000..0d687c5 --- /dev/null +++ b/abs/core/LinHES-system/msg.cfg @@ -0,0 +1,23 @@ +[default] +font_color=#ebb81c +display_time=5000 +position=1 +font_type=Overlock SC 40 + +[middle] +font_color=#ebb81c +display_time=5000 +position=4 +font_type=Overlock SC 40 + +[bottom] +font_color=#ebb81c +display_time=5000 +position=7 +font_type=Overlock SC 40 + +[alert] +font_color=red +display_time=5000 +position=4 +font_type=Overlock SC 40 diff --git a/abs/core/LinHES-system/myth_status.py b/abs/core/LinHES-system/myth_status.py index f0e41f3..0f2edfb 100644 --- a/abs/core/LinHES-system/myth_status.py +++ b/abs/core/LinHES-system/myth_status.py @@ -1,21 +1,12 @@ #!/usr/bin/python2 +#This program is called on login to display the status of mythtv tuners & recording status +#Also will display alerts generated by xymon. If the location of xymon changes, this script needs to be updated. + from MythTV import MythBE,MythDB,MythLog import datetime,time,sys,subprocess,re -try: - be = MythBE() - db = MythDB() -except: - print "\nCouldn't connect to MythTV service for status" - sys.exit(1) - -cursor = db.cursor() -now = datetime.datetime.now() -farout=99999999 -next_start_diff=datetime.timedelta(farout) -num_upcoming=12 +import os,glob def formatTD(td): - #print td days = td.days hours = td.seconds // 3600 minutes = (td.seconds % 3600) // 60 @@ -46,76 +37,223 @@ def formatTD(td): return_string = '%s%s%s%s' % (day_string, hour_string, minute_string, second_string) return return_string +def print_alerts(): + dir_name = "/home/xymon/var/login_alerts" + out_alert="" + try: + os.chdir(dir_name) + except: + pass + #print " myth_status: Couldn't change dir to %s" %dir_name + file_list=glob.glob("*") + + if len(file_list) == 0: + #print " myth_status: no alert files found" + pass + else: + for alert_file in file_list: + out_line='' + datahost = '' + dataservice = '' + datadown = '' + try: + #print " myth_staus: reading in %s" %alert_file + f=open(alert_file,'r') + lines=f.readlines() + f.close() + except: + #print " myth_status: Couldn't open %s for reading" %alert_file + continue + + for line in lines: + try: + data,value=line.split(":") + except: + continue #exception occured try the next line + + if data == 'HOST': + datahost = value.strip() + elif data == 'SERVICE': + dataservice = value.strip() + elif data == 'DOWN': + datadown = value.strip() + sec=int(datadown) + td_sec = datetime.timedelta(seconds=sec) + td_sec_formated = formatTD(td_sec) + + out_line =" %s on %s down for %s \n" %(dataservice, + datahost, + td_sec_formated) + out_alert += out_line + + print "System Alerts:" + print "---------------" + if len(out_alert) > 0: + print out_alert + print " Please see the system health webpage for more information" + else: + print " All systems OK" -a=be.getRecorderList() -header="#"*60 -print header -print "" -print "Tuner Status:" -print "-------------" -for i in a: - cmd="select cardtype,hostname from capturecard where cardid=%s;" %i + return - cursor.execute(cmd) - results=cursor.fetchall() - type = results[0][0] - hostname = results[0][1] - id = i - try: - c=be.getCurrentRecording(i) - if c.title == None: - current_recording = "Idle" + +#------------------------------------------- + + +class tuner_recording_status: + def __init__ (self,num_upcoming): + + self.now = datetime.datetime.now() + self.farout=99999999 + self.next_start_diff=datetime.timedelta(self.farout) + self.num_upcoming=num_upcoming + self.tuner_status_list=[] + self.conflict_list=[] + self.upcoming_list=[] + self.ur=0 + self.db_connection_status = self.check_database_connection() + if self.db_connection_status == 0: + self.tuner_status() + self.conflicts() + self.upcoming_recordings() + + def get_db_check_status(self): + return self.db_connection_status + + def check_database_connection(self): + rc=0 + try: + self.be = MythBE() + self.db = MythDB() + self.cursor = self.db.cursor() + except: + print "\nCouldn't connect to MythTV service for status" + rc=1 + return rc +#----- + def tuner_status(self): + a=self.be.getRecorderList() + for i in a: + outline='' + cmd="select cardtype,hostname from capturecard where cardid=%s;" %i + self.cursor.execute(cmd) + results=self.cursor.fetchall() + type = results[0][0] + hostname = results[0][1] + id = i + try: + c=self.be.getCurrentRecording(i) + if c.title == None: + current_recording = "Idle" + else: + current_recording = "Recording %s" %c.title + outline = " Tuner %s (%s) on %s : %s " %(id, type, hostname, current_recording) + self.tuner_status_list.append(outline) + except: + outline = " Tuner %s (%s) on %s : %s " %(id, type, hostname, "Tuner Error") + self.tuner_status_list.append(outline) + + def get_tuner_status(self): + return self.tuner_status + + def print_tuner_status(self): + print "Tuner Status:" + print "-------------" + if len(self.tuner_status_list) > 0 : + for line in self.tuner_status_list: + print line else: - current_recording = "Recording %s" %c.title - print " Tuner %s (%s) on %s : %s " %(id, type, hostname, current_recording) - except: - print " Tuner %s (%s) on %s : %s " %(id, type, hostname, "Tuner Error") - -print "" -print "Upcoming Recordings (Next %s Scheduled):" %(num_upcoming) -print "----------------------------------------" -a=be.getUpcomingRecordings() -r=0 -for i in a: - r += 1 - if r > num_upcoming: - break - - title_chan="%s (%s)" %(i.title, i.channame) - #remove timezone - start_time=re.split("[-+]\d\d:\d\d",str(i.starttime))[0] - start_time_struct=datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") - start_time_out=start_time_struct.strftime("%a %b %d %I:%M%p") - print " %s - %s - %s" %(start_time_out,i.hostname, title_chan) - diff = start_time_struct - now - if diff < next_start_diff : - next_start_diff = diff - - -print "" -print "Recording Conflicts:" -print "----------------------" -a=be.getConflictedRecordings() -c=0 -for i in a: - title_chan="%s (%s)" %(i.title, i.channame) - print " %s - %-50s " %(i.starttime,title_chan) - c=c+1 - -if c == 0: - print " No Conflicts" - -print "" - -if next_start_diff == datetime.timedelta(farout): - ur="No recordings are scheduled" -else: - ur=formatTD(next_start_diff) -print "The next recording starts in:" -print "-----------------------------" -print " %s" %(ur) -print "" -subprocess.call("/usr/LH/bin/diskspace.sh",shell=True) -print "" -print header + print " No tuners found" + +#-------- + def upcoming_recordings(self): + + a=self.be.getUpcomingRecordings() + r=0 + for i in a: + r += 1 + if r > self.num_upcoming: + break + + title_chan="%s (%s)" %(i.title, i.channame) + #remove timezone + start_time=re.split("[-+]\d\d:\d\d",str(i.starttime))[0] + start_time_struct=datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") + start_time_out=start_time_struct.strftime("%a %b %d %I:%M%p") + self.upcoming_list.append([start_time_out,i.hostname, title_chan]) + #print " %s - %s - %s" %(start_time_out,i.hostname, title_chan) + diff = start_time_struct - self.now + if diff < self.next_start_diff : + self.next_start_diff = diff + + if self.next_start_diff == datetime.timedelta(self.farout): + self.ur="No recordings are scheduled" + else: + self.ur=formatTD(self.next_start_diff) + + + def get_upcoming_recordings(self): + return self.upcoming_list + + def print_upcoming_recordings(self): + #print self.get_upcoming_recordings() + print "" + print "Upcoming Recordings (Next %s Scheduled):" %(self.num_upcoming) + print "----------------------------------------" + if len(self.get_upcoming_recordings()) > 0: + for i in self.get_upcoming_recordings(): + #print " %s - %s - %s" %(start_time_out,i.hostname, title_chan) + print " %s - %s - %s" %(i[0],i[1],i[2]) + else: + print " No upcoming recordings" + pass + + def get_next_start_time(self): + return self.ur + + def print_next_start_time(self): + print "" + print "The next recording starts in:" + print "-----------------------------" + print " %s" %(self.get_next_start_time()) + print "" + +#----- + + def conflicts(self): + a=self.be.getConflictedRecordings() + for i in a: + out_line='' + title_chan="%s (%s)" %(i.title, i.channame) + out_line=(i.starttime,title_chan) + self.conflict_list.append(out_line) + + def get_conflict_list(self): + return self.conflict_list + + def print_conflict_list(self): + print "" + print "Recording Conflicts:" + print "----------------------" + if len(self.get_conflict_list()) > 0: + for i in self.get_conflict_list(): + print " %s - %-50s " %(i[0],i[1]) + else: + print " No conflicts" + +#header="#"*60 + + +def go(): + tuner = tuner_recording_status(12) + if tuner.get_db_check_status() == 0: + tuner.print_tuner_status() + tuner.print_upcoming_recordings() + tuner.print_conflict_list() + tuner.print_next_start_time() + print_alerts() + + +if __name__ == "__main__": + go() |
