diff options
Diffstat (limited to 'gard-v2.py')
-rwxr-xr-x | gard-v2.py | 124 |
1 files changed, 32 insertions, 92 deletions
@@ -13,9 +13,11 @@ import datetime import subprocess import logging +import check + rmaxlag=45 -dmaxlag=5.5 -relmaxlag=2 +dmaxlag = 5.5 * 3600 +relmaxlag = 2 * 3600 HOME = os.getenv('HOME') reportpath = HOME + "/gentoo/mirrors/gard/reports" @@ -36,84 +38,6 @@ def add_handler(logfile): def remove_handler(handler): logging.getLogger('').removeHandler(handler) -def mirrorcheck(target): - retcode1=subprocess.call(['/usr/bin/wget','-q','-T 30',target]) - if retcode1 > 0: - logging.error("return value of wget during mirrorcheck was "+str(retcode1)) - return - else: - temp=open('timestamp.chk','r') - ots=temp.readline() - temp.close() - #Keep timestamp as Fri, 04 Jul 2008 20:45:01, remove the +0000 since there doesn't seem to be a %z in python - t1=time.mktime(time.strptime(ots.replace(" +0000",""), "%a, %d %b %Y %H:%M:%S ")) - lag=(time.mktime(time.gmtime())-t1)/(60*60) - gmt=time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) - if lag > dmaxlag: - error1 = "distfiles is over 5.5 hours behind, lag is : "+str(round(lag,2))+" hours" - tstamp1 = "Timestamp on Mirror : "+str(ots).strip() - curtime1 = "Current time in UTC : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) - bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate - logging.error(error1) - logging.info(tstamp1) - logging.info(curtime1) - logging.info(bugurl1) - else: - info1 = addy+" is in sync, current delta : "+str(round(lag,2))+" hours" - tstamp1 = "Timestamp on Mirror : "+str(ots) - curtime1 = "Current time in UTC : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) - bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate - logging.info(info1) - logging.info(tstamp1) - logging.info(curtime1) - logging.info(bugurl1) - os.unlink('timestamp.chk') - return - -def relpermcheck(target): - retcode2=subprocess.call(['/usr/bin/wget','-q','-T 30',target]) - if retcode2 < 1: - logging.error("return value of wget for /releases file perm check was "+str(retcode2)+" which means the file is world accessible!") - os.unlink('THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt') - return - -def reltscheck(target): - retcode3=subprocess.call(['/usr/bin/wget','-q','-T 30',target]) - if retcode3 > 0: - logging.error("return value of wget for release timestamp check was "+str(retcode3)) - return - else: - temp=open('timestamp.x','r') - ots=temp.readline() - temp.close() - ts=ots.split(' ') - nots=ts[1]+" "+ts[2]+" "+ts[3]+" "+ts[4]+" "+ts[5]+" " - #Keep timestamp as Fri, 04 Jul 2008 20:45:01, remove the +0000 since there doesn't seem to be a %z in python - t1=time.mktime(time.strptime(nots, "%a, %d %b %Y %H:%M:%S ")) - lag=(time.mktime(time.gmtime())-t1)/(60*60*24) - gmt=time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) - if lag > relmaxlag: - error3 = "releases is over 2 days behind, lag is : "+str(round(lag,2))+" days" - tstamp3 = "Timestamp on Mirror : "+nots - curtime3 = "Current time in UTC : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) - bugurl3 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate - logging.error(error3) - logging.info(tstamp3) - logging.info(curtime3) - logging.info(bugurl3) - else: - info3 = addy+"'s releases dir is in sync, current delta : "+str(round(lag,2))+" days" - tstamp3 = "Timestamp on Mirror : "+nots - curtime3 = "Current time in UTC : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) - bugurl3 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate - logging.info(info3) - logging.info(tstamp3) - logging.info(curtime3) - logging.info(bugurl3) - os.unlink('timestamp.x') - return - - retcode5=subprocess.call(['/usr/bin/wget','-q','-T 30', '-O', fname, bugurl]) file=open(fname,'r') logging.debug("Initializing G(entoo)A(utomated)R(sync)D(istfiles) checker script, version 2 (Katrina) - kicking mirror ass for Gentoo") @@ -203,12 +127,20 @@ for line in file: handler = add_handler(fname) info5 = addy+" wants to be distfiles mirror and is being checked as per Bug #"+bugnum+ " over http" logging.info(info5) - disttsdest=http+"/distfiles/timestamp.chk" - mirrorcheck(disttsdest) - reltsdest=http+"/releases/.test/timestamp.x" - reltscheck(reltsdest) - relpermdest=http+"/releases/.test/THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt" - relpermcheck(relpermdest) + + synced = True + if check.DistfilesCheck(http).check(dmaxlag) is not True: + synced = False + if check.ReleasesCheck(http).check(relmaxlag) is not True: + synced = False + if synced: + logging.info(addy + ' is in sync') + else: + logging.info(addy + ' is out of sync') + + bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate + logging.info(bugurl1) + # New line for the prettiness logging.info('') remove_handler(handler) @@ -221,12 +153,20 @@ for line in file: add_handler(fname) info6 = addy+" wants to be an distfiles mirror and is being checked as per Bug #"+bugnum+ " over ftp" logging.info(info6) - ftpdest=ftp+"/distfiles/timestamp.chk" - mirrorcheck(ftpdest) - reltsdest=ftp+"/releases/.test/timestamp.x" - reltscheck(reltsdest) - relpermdest=ftp+"/releases/.test/THIS-FILE-SHOULD-NOT-BE-PUBLIC.txt" - relpermcheck(relpermdest) + + synced = True + if check.DistfilesCheck(ftp).check(dmaxlag) is not True: + synced = False + if check.ReleasesCheck(ftp).check(relmaxlag) is not True: + synced = False + if synced: + logging.info(addy + ' is in sync') + else: + logging.info(addy + ' is out of sync') + + bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate + logging.info(bugurl1) + # New line for the prettiness logging.info('') remove_handler(handler) |