Exemplo n.º 1
0
 def check_args(self):
     global MOUNTS
     if self.opts.mounts:
         mounts = self.opts.mounts.split(',')
         MOUNTS = mounts
 
     # Try to get numeic warning/critical values
     s_warning  = self.opts.warning or DEFAULT_WARNING
     s_critical = self.opts.critical or DEFAULT_CRITICAL
     self.warning, self.critical = schecks.get_warn_crit(s_warning, s_critical)
 
     # Get Unit 
     self.s_unit = self.opts.unit or 'B'
Exemplo n.º 2
0
    def check_args(self):
        global MOUNTS
        if self.opts.mounts:
            mounts = self.opts.mounts.split(',')
            MOUNTS = mounts

        # Try to get numeic warning/critical values
        s_warning = self.opts.warning or DEFAULT_WARNING
        s_critical = self.opts.critical or DEFAULT_CRITICAL
        self.warning, self.critical = schecks.get_warn_crit(
            s_warning, s_critical)

        # Get Unit
        self.s_unit = self.opts.unit or 'B'
    # Ok first job : parse args
    opts, args = parser.parse_args()
    if args:
        parser.error("Does not accept any argument.")

    port = opts.port
    hostname = opts.hostname or ''

    ssh_key_file = opts.ssh_key_file or os.path.expanduser('~/.ssh/id_rsa')
    user = opts.user or 'shinken'
    passphrase = opts.passphrase or ''

    # Try to get numeic warning/critical values
    s_warning = opts.warning or DEFAULT_WARNING
    s_critical = opts.critical or DEFAULT_CRITICAL
    warning, critical = schecks.get_warn_crit(s_warning, s_critical)

    # Ok now connect, and try to get values for memory
    client = schecks.connect(hostname, port, ssh_key_file, passphrase, user)
    total, used, free, shared, buffed, cached, swap_total, swap_used, swap_free = get_meminfo(
        client)

    # Maybe we failed at getting data
    if total == 0:
        print "Error : cannot fetch memory values from host"
        sys.exit(2)

    # Ok analyse data
    pct_used = 100 * float(used - buffed - cached) / total
    pct_used = int(pct_used)
    if args:
        parser.error("Does not accept any argument.")

    hostname = opts.hostname
    if not hostname:
        print "Error : hostname parameter (-H) is mandatory"
        sys.exit(2)

    ssh_key_file = opts.ssh_key_file or os.path.expanduser('~/.ssh/id_rsa')
    user = opts.user or 'shinken'
    passphrase = opts.passphrase or ''

    # Try to get numeic warning/critical values
    s_warning  = opts.warning or DEFAULT_WARNING
    s_critical = opts.critical or DEFAULT_CRITICAL
    warning, critical = schecks.get_warn_crit(s_warning, s_critical)

    # Ok now connect, and try to get values for memory
    client = schecks.connect(hostname, ssh_key_file, passphrase, user)
    diff, stats = get_kernel_stats(client)
    
    # Maybe we failed at getting data
    if not stats:
        print "Error : cannot fetch cpu stats values from host"
        sys.exit(2)

    # We are putting diff into float so we are sure we will have float everywhere
    diff = float(diff)

    perfdata = []
    for k in ['ctxt', 'processes', 'pgfault', 'pgmajfault']: