Esempio n. 1
0
def verifyHelper(filename, dict, fix_rrd=False):
    """
    Helper function for verifyRRD.  Checks one file,
    prints out errors.  if fix_rrd, will attempt to
    dump out rrd to xml, add the missing attributes,
    then restore.  Original file is obliterated.

    @param filename: filename of rrd to check
    @param dict: expected dictionary
    @param fix_rrd: if true, will attempt to add missing attrs
    """
    global rrd_problems_found
    if not os.path.exists(filename):
        print("WARNING: %s missing, will be created on restart" % (filename))
        return
    rrd_obj = rrdSupport.rrdSupport()
    (missing, extra) = rrd_obj.verify_rrd(filename, dict)
    for attr in extra:
        print("ERROR: %s has extra attribute %s" % (filename, attr))
        if fix_rrd:
            print("ERROR: fix_rrd cannot fix extra attributes")
    if not fix_rrd:
        for attr in missing:
            print("ERROR: %s missing attribute %s" % (filename, attr))
        if len(missing) > 0:
            rrd_problems_found = True
    if fix_rrd and (len(missing) > 0):
        (f, tempfilename) = tempfile.mkstemp()
        (out, tempfilename2) = tempfile.mkstemp()
        (restored, restoredfilename) = tempfile.mkstemp()
        backup_str = str(int(time.time())) + ".backup"
        print("Fixing %s... (backed up to %s)" %
              (filename, filename + backup_str))
        os.close(out)
        os.close(restored)
        os.unlink(restoredfilename)
        # Use exe version since dump, restore not available in rrdtool
        dump_obj = rrdSupport.rrdtool_exe()
        outstr = dump_obj.dump(filename)
        for line in outstr:
            os.write(f, "%s\n" % line)
        os.close(f)
        # Move file to backup location
        shutil.move(filename, filename + backup_str)
        rrdSupport.addDataStore(tempfilename, tempfilename2, missing)
        outstr = dump_obj.restore(tempfilename2, restoredfilename)
        os.unlink(tempfilename)
        os.unlink(tempfilename2)
        shutil.move(restoredfilename, filename)
    if len(extra) > 0:
        rrd_problems_found = True
def verifyHelper(filename,dict, fix_rrd=False):
    """
    Helper function for verifyRRD.  Checks one file,
    prints out errors.  if fix_rrd, will attempt to
    dump out rrd to xml, add the missing attributes,
    then restore.  Original file is obliterated.

    @param filename: filename of rrd to check
    @param dict: expected dictionary
    @param fix_rrd: if true, will attempt to add missing attrs
    """
    global rrd_problems_found
    if not os.path.exists(filename):
        print "WARNING: %s missing, will be created on restart" % (filename)
        return
    rrd_obj=rrdSupport.rrdSupport()
    (missing,extra)=rrd_obj.verify_rrd(filename,dict)
    for attr in extra:
        print "ERROR: %s has extra attribute %s" % (filename,attr)
        if fix_rrd:
            print "ERROR: fix_rrd cannot fix extra attributes"
    if not fix_rrd:
        for attr in missing:
            print "ERROR: %s missing attribute %s" % (filename,attr)
        if len(missing) > 0:
            rrd_problems_found=True
    if fix_rrd and (len(missing) > 0):
        (f,tempfilename)=tempfile.mkstemp()
        (out,tempfilename2)=tempfile.mkstemp()
        (restored,restoredfilename)=tempfile.mkstemp()
        backup_str=str(int(time.time()))+".backup"
        print "Fixing %s... (backed up to %s)" % (filename,filename+backup_str)
        os.close(out)
        os.close(restored)
        os.unlink(restoredfilename)
        #Use exe version since dump, restore not available in rrdtool
        dump_obj=rrdSupport.rrdtool_exe()
        outstr=dump_obj.dump(filename)
        for line in outstr:
            os.write(f,"%s\n"%line)
        os.close(f)
        #Move file to backup location 
        shutil.move(filename,filename+backup_str)
        rrdSupport.addDataStore(tempfilename,tempfilename2,missing)
        outstr=dump_obj.restore(tempfilename2,restoredfilename)
        os.unlink(tempfilename)
        os.unlink(tempfilename2)
        shutil.move(restoredfilename,filename)
    if len(extra) > 0:
        rrd_problems_found=True
    def __init__(self):
        # set default values
        # user should modify if needed
        self.rrd_step=300       #default to 5 minutes
        self.rrd_heartbeat=1800 #default to 30 minutes, should be at least twice the loop time
        self.rrd_archives=[('AVERAGE',0.8,1,740),      # max precision, keep 2.5 days
                           ('AVERAGE',0.92,12,740),       # 1 h precision, keep for a month (30 days)
                           ('AVERAGE',0.98,144,740)        # 12 hour precision, keep for a year
                           ]

        # The name of the attribute that identifies the glidein
        self.monitor_dir="monitor/"

        self.rrd_obj=rrdSupport.rrdSupport()

        self.my_name="Unknown"
Esempio n. 4
0
    def __init__(self):
        # set default values
        # user should modify if needed
        self.rrd_step=300       #default to 5 minutes
        self.rrd_heartbeat=1800 #default to 30 minutes, should be at least twice the loop time
        self.rrd_archives=[('AVERAGE', 0.8, 1, 740),      # max precision, keep 2.5 days
                           ('AVERAGE', 0.92, 12, 740),       # 1 h precision, keep for a month (30 days)
                           ('AVERAGE', 0.98, 144, 740)        # 12 hour precision, keep for a year
                           ]

        # The name of the attribute that identifies the glidein
        self.monitor_dir="monitor/"

        self.rrd_obj=rrdSupport.rrdSupport()

        self.my_name="Unknown"
Esempio n. 5
0
    def __init__(self, config, configAgg):
        # Get Default Config from Parent
        super(Monitoring_Output, self).__init__()

        # Set Default Config for this Child
        for key in DEFAULT_CONFIG:
            self.config[key] = DEFAULT_CONFIG[key]

        for key in DEFAULT_CONFIG_AGGR:
            self.configAggr[key] = DEFAULT_CONFIG_AGGR[key]

        # Set Config from Pass Parameters (from the Frontend XML Config File)
        for key in config:
            self.config[key] = config[key]

        for key in configAgg:
            self.configAggr[key] = configAgg[key]

        self.rrd_obj = rrdSupport.rrdSupport()

        self.updated = time.time()

        # Used in verification
        self.rrd_problems_found = False