#!/usr/bin/python -tt # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # (c) 2007 Red Hat, Inc - Written by Seth Vidal skvidal at fedoraproject.org # command line or nagios-plugin to check to make sure # a given repo is correct/valid # take url # append repodata (if it doesn't already have it) # download repomd.xml # parse out checksums # download each item from the file # checksum them # for each of the xml files, run xmllint --noout over there and check return # codes # return nothing if all is well # scream holy fuck if they are broken import sys from yum import repoMDObject from yum.misc import checksum import urlgrabber import tempfile import subprocess import os def main(myurl): tempdir = tempfile.mkdtemp() errorstrings = [] if myurl[-1] != '/': myurl += '/' baseurl = myurl if not myurl.endswith('repodata/'): myurl += 'repodata/' else: baseurl = baseurl.replace('repodata/', '/') rf = myurl + 'repomd.xml' try: rm = urlgrabber.urlopen(rf) repomd = repoMDObject.RepoMD('foo', rm) for t in repomd.fileTypes(): data = repomd.getData(t) base, href = data.location if base: loc = base + '/' + href else: loc = baseurl + href destfn = tempdir + '/' + os.path.basename(href) dest = urlgrabber.urlgrab(loc, destfn) ctype, known_csum = data.checksum csum = checksum(ctype, dest) if csum != known_csum: errorstrings.append("checksum: %s" % t) if href.find('xml') != -1: retcode = subprocess.call(['/usr/bin/xmllint', '--noout', dest]) if retcode != 0: errorstrings.append("failed xml read: %s" % t) except urlgrabber.grabber.URLGrabError, e: errorstrings.append('Error accessing repository %s' % e) if errorstrings: print ','.join(errorstrings) return 2 else: print "OK all checked out" return 0 if __name__ == '__main__': if len(sys.argv) < 2: print "Usage:\n sanity-check-repodata \n\n" sys.exit(4) sys.exit(main(sys.argv[1]))