Example #1
0
def publishPassiveResultNSCA(bin, conf, host, port, reslist, delim=';'):
    """Form and run NSCA command to publish passive results.

    :Parameters:
      - `bin`  NSCA binary (full path)
      - `conf` NSCA configuration file
      - `host` NSCA server
      - `port` (`str`) NSCA port
      - `reslist` (`list`) list of results. Elements can be strings or
        dictionaries. In case of dictionaries `__getPassiveResultString()` is
        used to flatten the `dict` to get proper the result representing string.
      - `delim` delimiter for the fields in the results string

    :raises `ErrNagiosLib`: on a problem invoking NSCA client.
    """

    if isinstance(reslist[0], dict):
        reslist = __getPassiveResultString(reslist, delim=delim)

    cmd = '%s -c %s -H %s -p %s -d "%s"' % (bin, conf, host, port, delim)
    for r in reslist:
        try:
            run_cmd_data(cmd, r + '\n')
        except Exception, e:
            raise ErrNagiosLib, \
                'Problem invoking NSCA client. %s' % str(e)
Example #2
0
def publishPassiveResultNSCA(bin, conf, host, port, reslist, delim=';'):
    """Form and run NSCA command to publish passive results.

    :Parameters:
      - `bin`  NSCA binary (full path)
      - `conf` NSCA configuration file
      - `host` NSCA server
      - `port` (`str`) NSCA port
      - `reslist` (`list`) list of results. Elements can be strings or
        dictionaries. In case of dictionaries `__getPassiveResultString()` is
        used to flatten the `dict` to get proper the result representing string.
      - `delim` delimiter for the fields in the results string

    :raises `ErrNagiosLib`: on a problem invoking NSCA client.
    """

    if isinstance(reslist[0], dict):
        reslist = __getPassiveResultString(reslist, delim=delim)

    cmd = '%s -c %s -H %s -p %s -d "%s"' % (bin,
                        conf, host, port, delim)
    for r in reslist:
        try:
            run_cmd_data(cmd, r+'\n')
        except Exception, e:
            raise ErrNagiosLib, \
                'Problem invoking NSCA client. %s' % str(e)
Example #3
0
def cmp_version_ge(v, cmd, prefix):
    """Check if installed version is >= to a given one.

    @param cmd: command to use (eg. C{gfal_version})
    @type cmd: L{str}
    @param prefix: package/library name to strip off (eg. C{GFAL-client})
    @type prefix: C{str}

    @return: L{int} in range: (-3 .. 1)
      - 1 - installed version is >= of the given one
      - 0 - installed version is < than the given one
      - <0 - couldn't perform comparison
          - -1 - problem interpreting current version
          - -2 - problem interpreting given version
          - -3 - couldn't determine current version number
    @rtype: L{int}
    """
    stdout = ''
    try:
        stdout = samutils.run_cmd_data(cmd)
    except StandardError,e:
        stdout = str(e)
        if re.search('command not found',stdout):
            return -3
Example #4
0
def cmp_version_ge(v, cmd, prefix):
    """Check if installed version is >= to a given one.

    @param cmd: command to use (eg. C{gfal_version})
    @type cmd: L{str}
    @param prefix: package/library name to strip off (eg. C{GFAL-client})
    @type prefix: C{str}

    @return: L{int} in range: (-3 .. 1)
      - 1 - installed version is >= of the given one
      - 0 - installed version is < than the given one
      - <0 - couldn't perform comparison
          - -1 - problem interpreting current version
          - -2 - problem interpreting given version
          - -3 - couldn't determine current version number
    @rtype: L{int}
    """
    stdout = ''
    try:
        stdout = samutils.run_cmd_data(cmd)
    except StandardError, e:
        stdout = str(e)
        if re.search('command not found', stdout):
            return -3