def execute(self): ip, _port = self.get_address() cmd = 'dhcping' path = which(cmd) if not path: return (Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH'])) if not is_setuid_root(path): return Event.DOWN, '%s must be setuid root' % path try: proc = subprocess.Popen( [path, '-i', # Use inform packet so we don't have to be valid client '-s', ip, '-t', str(self.timeout), # Timeout in seconds ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() proc.stdout.read() stderr = proc.stderr.read() if proc.returncode != 0: return Event.DOWN, repr(stderr.strip()) except IOError as msg: return Event.DOWN, 'Could not run dhcping: %s' % msg return Event.UP, 'OK'
def execute(self): username = self.args.get('username', '') if not username: return Event.DOWN, "Missing required argument: username" ip, _port = self.get_address() cmd = 'rpcclient' cmdpath = which(cmd) if not cmdpath: return (Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH'])) try: proc = subprocess.Popen( [cmdpath, '-U', '%', '-c', 'lookupnames ' + username, ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() except OSError as msg: return Event.DOWN, 'could not run rpcclient: %s' % msg if proc.returncode != 0: errline = proc.stdout.readline() return (Event.DOWN, "rpcclient returned %s: %s" % (proc.returncode, errline)) output = proc.stdout.readlines() lastline = output[-1] if lastline.split()[0] == username: return Event.UP, 'Ok' else: return Event.DOWN, lastline
def execute(self): ip, port = self.getAddress() args = self.getArgs() host = args.get('hostname', ip) username = args.get('username', '') password = args.get('password', '') workgroup = args.get('workgroup', '') cmdpath = which(SMBCLIENT) if not cmdpath: return (Event.DOWN, 'Command %s not found in %s' % (SMBCLIENT, os.environ['PATH'])) args = [cmdpath, '-L', host, '-p', str(port)] if password and username: args += ['-U', username + '%' + password] if workgroup: args += ['-W', workgroup] else: args += ['-N'] try: proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() except IOError, msg: return Event.DOWN, 'could not run smbclient: %s' % msg
def execute(self): ip, _port = self.getAddress() timeout = self.getTimeout() cmd = 'dhcping' path = which(cmd) if not path: return (Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH'])) if not is_setuid_root(path): return Event.DOWN, '%s must be setuid root' % path try: proc = subprocess.Popen( [path, '-i', # Use inform packet so we don't have to be valid client '-s', ip, '-t', str(timeout), # Timeout in seconds ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() proc.stdout.read() stderr = proc.stderr.read() if proc.returncode != 0: return Event.DOWN, repr(stderr.strip()) except IOError, msg: return Event.DOWN, 'Could not run dhcping: %s' % msg
def execute(self): args = self.getArgs() username = args.get('username', '') if not username: return Event.DOWN, "Missing required argument: username" ip, _port = self.getAddress() cmd = 'rpcclient' cmdpath = which(cmd) if not cmdpath: return (Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH'])) try: proc = subprocess.Popen([cmdpath, '-U', '%', '-c', 'lookupnames ' + username, ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() except OSError, msg: return Event.DOWN, 'could not run rpcclient: %s' % msg
def execute(self): # map service to t=tcp or u=udp mapper = { 'nfs': 't', 'status': 't', 'nlockmgr': 'u', 'mountd': 't', 'ypserv': 'u', 'ypbind': 'u', } default = ['nfs', 'nlockmgr', 'mountd', 'status'] required = self.args.get('required', '') if not required: required = default else: required = required.split(',') cmd = 'rpcinfo' cmdpath = which(cmd) if not cmdpath: return ( Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH']), ) ip, _port = self.get_address() for service in required: protocol = mapper.get(service, '') if not protocol: return ( Event.DOWN, "Unknown argument: [%s], can only check " "%s" % (service, str(mapper.keys())), ) try: proc = subprocess.Popen( [cmdpath, '-' + protocol, ip, service], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) proc.wait() except OSError as msg: return Event.DOWN, 'could not run rpcinfo: %s' % msg output = proc.stdout.read() if 'ready' in output: continue if 'not available' in output: return Event.DOWN, '%s not available' % service if not output: return Event.DOWN, 'rpcinfo timed out' return Event.UP, "Ok"
def execute(self): args = self.getArgs() # map service to t=tcp or u=udp mapper = { 'nfs': 't', 'status': 't', 'nlockmgr': 'u', 'mountd': 't', 'ypserv': 'u', 'ypbind': 'u', } default = ['nfs', 'nlockmgr', 'mountd', 'status'] required = args.get('required', '') if not required: required = default else: required = required.split(',') cmd = 'rpcinfo' cmdpath = which(cmd) if not cmdpath: return (Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH'])) ip, _port = self.getAddress() for service in required: protocol = mapper.get(service, '') if not protocol: return (Event.DOWN, "Unknown argument: [%s], can only check " "%s" % (service, str(mapper.keys()))) try: proc = subprocess.Popen([cmdpath, '-'+protocol, ip, service], stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() except OSError, msg: return Event.DOWN, 'could not run rpcinfo: %s' % msg output = proc.stdout.read() if 'ready' in output: continue if 'not available' in output: return Event.DOWN, '%s not available' % service if not output: return Event.DOWN, 'rpcinfo timed out'
def execute(self): ip, port = self.get_address() args = self.args host = args.get('hostname', ip) username = args.get('username', '') password = args.get('password', '') workgroup = args.get('workgroup', '') cmdpath = which(SMBCLIENT) if not cmdpath: return (Event.DOWN, 'Command %s not found in %s' % (SMBCLIENT, os.environ['PATH'])) args = [cmdpath, '-L', host, '-p', str(port)] if password and username: args += ['-U', username + '%' + password] if workgroup: args += ['-W', workgroup] else: args += ['-N'] try: proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() except IOError as msg: return Event.DOWN, 'could not run smbclient: %s' % msg output = proc.stdout.read() errput = proc.stderr.read() match = (SMBCLIENT_PATTERN.search(output) or SMBCLIENT_PATTERN.search(errput)) if match: version = ' '.join(match.groups()) self.version = version return Event.UP, 'OK' else: return Event.DOWN, 'error %s' % output.strip().split('\n')[-1]
def execute(self): args = self.getArgs() username = args.get('username', '') if not username: return Event.DOWN, "Missing required argument: username" ip, _port = self.getAddress() cmd = 'rpcclient' cmdpath = which(cmd) if not cmdpath: return (Event.DOWN, 'Command %s not found in %s' % (cmd, os.environ['PATH'])) try: proc = subprocess.Popen( [cmdpath, '-U', '%', '-c', 'lookupnames ' + username, ip], stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() except OSError, msg: return Event.DOWN, 'could not run rpcclient: %s' % msg