예제 #1
0
def main():
    """The script"""

    options = {
        'detailed': ('Report detailed information', None, 'store_true', False, 'D'),
        'moabxml': ('File containing moab XML data (only for testing)', None, 'store', None),
        'max-retries': ('Maximum number retries prior to going critical', 'int', 'store', 2),
        'retry-interval': ('Seconds in between retries', 'int', 'store', 60),
    }

    opts = ExtendedSimpleOption(options)

    msg = "show_stats completed (%d tries)"
    try:
        if opts.options.moabxml:
            try:
                moabxml = open(opts.options.moabxml).read()
            except (IOError, OSError):
                logger.raiseException('Failed to read moab xml from %s' % opts.options.moabxml)
        else:
            moabxml = None

        retry = 0
        for retry in xrange(0, opts.options.max_retries):
            moab_stats = showstats(xml=moabxml)
            if moab_stats:
                break
            else:
                logger.info("Sleeping after retry %d" % (retry + 1,))
                time.sleep(opts.options.retry_interval)

        if not moab_stats:
            logger.error("Moabs showstats dit not provide useful output after %d, likely timed out." % (retry + 1,))
            opts.critical("Moabs showstats failed running correctly (%d retries)" % (retry + 1,))
            sys.exit(NAGIOS_EXIT_CRITICAL)

        else:
            stats = moab_stats['summary']

            if opts.options.detailed:
                detailed_info_string = """Shortterm/Longterm efficiency %.3f/%.3f
Dedicate/total prochours %s/%s
Active/Total procs %s/%s""" % (stats['STE'], stats['LTE'],
                               stats['DPH'], stats['TPH'],
                               stats['CAP'], stats['CTP'],)
                logger.info("detailed result STE = %s LTE = %s DPH = %s TPH = %s CAP = %s CTP = %s" %
                            (stats['STE'], stats['LTE'],
                             stats['DPH'], stats['TPH'],
                             stats['CAP'], stats['CTP'],))
                print detailed_info_string

            info_string = "short %.3f long %.3f" % (stats['STE'], stats['LTE'])
            logger.info("result: %s" % (info_string,))
            msg = msg % (retry + 1,)
            msg += " %s" % (info_string,)
    except Exception, err:
        logger.exception("critical exception caught: %s" % (err))
        opts.critical("Script failed in a horrible way")
        sys.exit(NAGIOS_EXIT_CRITICAL)
예제 #2
0
def main():
    """The script"""

    options = {
        'detailed':
        ('Report detailed information', None, 'store_true', False, 'D'),
        'moabxml': ('File containing moab XML data (only for testing)', None,
                    'store', None),
        'max-retries':
        ('Maximum number retries prior to going critical', 'int', 'store', 2),
        'retry-interval': ('Seconds in between retries', 'int', 'store', 60),
    }

    opts = ExtendedSimpleOption(options)

    msg = "show_stats completed (%d tries)"
    try:
        if opts.options.moabxml:
            try:
                moabxml = open(opts.options.moabxml).read()
            except (IOError, OSError):
                logger.raiseException('Failed to read moab xml from %s' %
                                      opts.options.moabxml)
        else:
            moabxml = None

        retry = 0
        for retry in xrange(0, opts.options.max_retries):
            moab_stats = showstats(xml=moabxml)
            if moab_stats:
                break
            else:
                logger.info("Sleeping after retry %d" % (retry + 1, ))
                time.sleep(opts.options.retry_interval)

        if not moab_stats:
            logger.error(
                "Moabs showstats dit not provide useful output after %d, likely timed out."
                % (retry + 1, ))
            opts.critical(
                "Moabs showstats failed running correctly (%d retries)" %
                (retry + 1, ))
            sys.exit(NAGIOS_EXIT_CRITICAL)

        else:
            stats = moab_stats['summary']

            if opts.options.detailed:
                detailed_info_string = """Shortterm/Longterm efficiency %.3f/%.3f
Dedicate/total prochours %s/%s
Active/Total procs %s/%s""" % (
                    stats['STE'],
                    stats['LTE'],
                    stats['DPH'],
                    stats['TPH'],
                    stats['CAP'],
                    stats['CTP'],
                )
                logger.info(
                    "detailed result STE = %s LTE = %s DPH = %s TPH = %s CAP = %s CTP = %s"
                    % (
                        stats['STE'],
                        stats['LTE'],
                        stats['DPH'],
                        stats['TPH'],
                        stats['CAP'],
                        stats['CTP'],
                    ))
                print detailed_info_string

            info_string = "short %.3f long %.3f" % (stats['STE'], stats['LTE'])
            logger.info("result: %s" % (info_string, ))
            msg = msg % (retry + 1, )
            msg += " %s" % (info_string, )
    except Exception, err:
        logger.exception("critical exception caught: %s" % (err))
        opts.critical("Script failed in a horrible way")
        sys.exit(NAGIOS_EXIT_CRITICAL)
예제 #3
0
           'nagios':('Report in nagios format', None, 'store_true', False, 'n'),
           'moabxml':('Use xml moab data from file (for testing)', None, 'store', None),
           }

go = simple_option(options)

if go.options.moabxml:
    try:
        moabxml = open(go.options.moabxml).read()
    except:
        _log.error('Failed to read moab xml from %s' % go.options.moabxml)
else:
    moabxml = None

try:
    stats = showstats(xml=moabxml)
    summary_stats = stats['summary']
except Exception, err:
    _log.error("Getting showstats failed with error %s" % (err))
    sys.exit(2)

if go.options.nagios:
    header = "show_stats OK"
    summ = "short %.3f long %.3f" % (summary_stats['STE'], summary_stats['LTE'])
    summary = "STE=%.1f LTE=%.1f DPH=%.0f TPH=%.0f AP=%s TP=%s"
    values = tuple([summary_stats[x] for x in ['STE', 'LTE', 'DPH', 'TPH', 'CAP', 'CTP']])

    # first 2 in
    msg = "%s - %s | %s" % (header, summ, summary % values)

    print msg
예제 #4
0
def main():
    """The script"""

    options = {
        "detailed": ("Report detailed information", None, "store_true", False, "D"),
        "moabxml": ("Use xml moab data from file (for testing)", None, "store", None),
        "max-retries": ("Maximum number retries prior to going critical", "int", "store", 2),
        "retry-interval": ("Seconds in between retries", "int", "store", 60),
    }

    opts = ExtendedSimpleOption(options)

    msg = "show_stats completed (%d tries)"
    try:
        if opts.options.moabxml:
            try:
                moabxml = open(opts.options.moabxml).read()
            except:
                logger.raiseException("Failed to read moab xml from %s" % opts.options.moabxml)
        else:
            moabxml = None

        for retry in xrange(0, opts.options.max_retries):
            moab_stats = showstats(xml=moabxml)
            if moab_stats:
                break
            else:
                logger.info("Sleeping after retry %d" % (retry + 1,))
                time.sleep(opts.options.retry_interval)

        if not moab_stats:
            logger.error("Moabs showstats dit not provide useful output after %d, likely timed out." % (retry + 1,))
            opts.critical("Moabs showstats failed running correctly (%d retries)" % (retry + 1,))
            sys.exit(NAGIOS_EXIT_CRITICAL)

        else:
            stats = moab_stats["summary"]

            if opts.options.detailed:
                detailed_info_string = """Shortterm/Longterm efficiency %.3f/%.3f
Dedicate/total prochours %s/%s
Active/Total procs %s/%s""" % (
                    stats["STE"],
                    stats["LTE"],
                    stats["DPH"],
                    stats["TPH"],
                    stats["CAP"],
                    stats["CTP"],
                )
                logger.info(
                    "detailed result STE = %s LTE = %s DPH = %s TPH = %s CAP = %s CTP = %s"
                    % (stats["STE"], stats["LTE"], stats["DPH"], stats["TPH"], stats["CAP"], stats["CTP"])
                )
                print detailed_info_string

            info_string = "short %.3f long %.3f" % (stats["STE"], stats["LTE"])
            logger.info("result: %s" % (info_string,))
            msg = msg % (retry + 1,)
            msg += " %s" % (info_string,)
    except Exception, err:
        logger.exception("critical exception caught: %s" % (err))
        opts.critical("Script failed in a horrible way")
        sys.exit(NAGIOS_EXIT_CRITICAL)