Example #1
0
def snmpResult2RRD3(host):
    dOid_to_Res = dict()

    for i, o in enumerate(host.oids):
        dOid_to_Res[o] = host.results[i]

    lOids = dOid_to_Res.keys()
    #
    # sort oids to guarantee proper o.alias's order:
    lOids.sort(commonFuncs.sortOids)


    inioverride = '%s/%s.override' % (host.hostdir, host.ifacesfile)

    if os.access(inioverride, os.F_OK):
        ifnamesOverride = ConfigParser.ConfigParser()
        ifnamesOverride.read(inioverride)
        ifnamesPairs = [ (int(index), value)
                for index, value in ifnamesOverride.items('ifnames') ]
    else:
        ifnamesPairs = host.ifnamesDict.items()


    for index, ifname in ifnamesPairs:

        lDsValues = []

        for o in lOids:
            # if index in dOid_to_Res[o].keys():
            if dOid_to_Res[o].get(index):
                value = dOid_to_Res[o][index]
            else:
                #
                # Arggh! Some HC tables may not contain
                # some indexes.
                value = 'U'

            lDsValues.append(value)

        # try to update RRD base:
        # template = ':'.join(lDsNames)
        updstr = 'N:%s' % ':'.join([str(v) for v in lDsValues])

        rrdbase = '%s/%s.rrd' % (
                            host.hostdir,
                            commonFuncs.cleanIfName(ifname)
                        )

        try:
            rrdtool.update(
                            rrdbase,
                            updstr
                          )
        #except:
        #       print "Error in update (%s, %s)" % (host.hostname, iface)
        except Exception, why:
            print "Error in update (%s, %s) - %s" % (
                            host.hostname,
                            index,
                            why )
Example #2
0
def snmpResult2RRD(host, dOid_to_Res):

    lDsNames = []

    lOids = dOid_to_Res.keys()
    #
    # sort oids to guarantee proper o.alias's order:
    lOids.sort(commonFuncs.sortOids)

    for o in lOids: 
        lDsNames.append(o.alias)


    for index, ifname in host.ifnamesDict.items():

        lDsValues = []

        for o in lOids:
            # if index in dOid_to_Res[o].keys():
            if dOid_to_Res[o].get(index):
                value = dOid_to_Res[o][index]
            else:
                #
                # Arggh! Some HC tables may not contain
                # some indexes.
                value = 'U'

            lDsValues.append(value)

        # try to update RRD base:
        # template = ':'.join(lDsNames)
        updstr = 'N:%s' % ':'.join(lDsValues)

        rrdbase = '%s/%s.rrd' % (
                            host.hostdir,
                            commonFuncs.cleanIfName(ifname)
                        )

        try:
            rrdtool.update(
                            rrdbase,
                            updstr
                          )
        #except:
        #       print "Error in update (%s, %s)" % (host.hostname, iface)
        except Exception, why:
            print "Error in update (%s, %s) - %s" % (
                            host.hostname,
                            index,
                            why )
Example #3
0
def checkBase(host):
    """Checks RRD base existence.

    Returns None if RRD base for any interface
    does not exist or not writable;
    returns path to hostdir if it's OK.

    Does not check validity of RRD base.
    """

    hostdir = host.hostdir

    #
    # Check hostdir:
    #
    if not os.access(hostdir, os.F_OK):
        # try to create
        try:
            os.mkdir(hostdir)
        except OSError:
            # should go to log?..
            print 'Error: can not create %s.' % hostdir
            return None

    elif not os.access(hostdir, os.W_OK):
        # not writable
        # should go to log?..
        print 'Error: %s in not writable.' % hostdir
        return None

    #
    # check/create RRD base:
    #
    # get descrs:
    host.getIfNames()

    #
    # For every key in ifnamesDict
    # an RRD base should exist.
    #
    for index, ifname in host.ifnamesDict.items():
        ifname = str(ifname)
        rrdbase = '%s/%s.rrd' % (hostdir, ifname)

        # replace '/' in interface name:
        rrdbase = rrdbase.replace(
                ifname,
                commonFuncs.cleanIfName(ifname))

        # is rrdbase exist?
        if os.access(rrdbase, os.F_OK):
            # is it writable?
            if not os.access(rrdbase, os.W_OK):
                print 'Not writable %s' % rrdbase
                return None
        else:
            # try to create rrdbase for iface `key':
            # print "try to create rrdbase %s for iface `%s'" % \
            #                 (rrdbase, ifnamesDict[key])

            #
            # Collect DSs for this port:
            #
            allDS = ()
            lOids = host.oids
            #
            # sort oids to guarantee proper o.alias's order:
            lOids.sort(commonFuncs.sortOids)
            for o in lOids:
                allDS = allDS + ( DS % (o.alias, hbeat, min, max) ,)

                # print (allDS + RRAcreateparams)
            try:
                rrdtool.create(
                                rrdbase,
                                '-s %s' % step,
                                *(allDS + RRAcreateparams)
                              )
            except:
                # should go in log?
                print 'ERROR: Can not create %s.' % rrdbase
                return None

    return hostdir
Example #4
0
File: tg.py Project: brownian/SPyBG
                    cf == 'max' and ' selected' or '',
                    loga and ' checked' or '',
                    loga and ' ' or ' disabled',
                    logarange == "auto" and ' selected' or '',
                    logarange == "min" and ' selected' or '',
                    logarange == "tiny" and ' selected' or '',
                    logarange == "med" and ' selected' or '',
                    logarange == "lar" and ' selected' or '',
                    logarange == "max" and ' selected' or '',
                )


        for i, k in enumerate(ifaceskeys):
            ifaceName = targetDEVICE.ifacesDict.get(str(k))
            ifaceAlias = targetDEVICE.ifaliasesDict.get(str(k))
            ifaceNameCleaned = commonFuncs.cleanIfName(ifaceName)

            rrdb = '%s/%s/%s.rrd' % (
                    rrddir,
                    targetDEVICE.hostname,
                    ifaceNameCleaned
                )
            picshortname = '%s_%s.png' % (
                        targetDEVICE.hostname,
                        ifaceNameCleaned
                    )
            picname = '%s/%s' % (picturepath, picshortname)
            pictitle = '%s: %s' % (
                    ifaceName,
                    ifaceAlias or '(No descr)'
                )