def is_agent_okconfig(self): """returns true if host responds to check_nrpe commands""" returncode, stdout, stderr = runCommand( "check_nrpe -H '%s' -c get_disks") if returncode == 0: return True if returncode == 1: return False return None
def is_agent_responding(self): """returns true if host responds to check_nrpe commands""" returncode, stdout, stderr = runCommand("check_nrpe -H '%s'" % self.ipaddress) if returncode == 0: return True if returncode == 1: return False return None
def install_nsclient(remote_host, domain, username, password): """ Logs into remote (windows) host and installs NSClient. Args: remote_host -- Hostname/IPAddress of remote host username -- Name of a user with administrative privileges on the remote host password -- Password to use Returns: True if operation was successful. Otherwise False """ if not network_scan.check_tcp(remote_host, 445, timeout=5): raise OKConfigError('Cannot reach remote_host on port 445, aborting...') # Try to authenticate with remote host and run a test command authcommand = 'winexe --reinstall -U "%s/%s%%%s" "//%s" "cmd /c echo test"' % (domain,username,password,remote_host) result = helper_functions.runCommand(authcommand) if result[0] != 0: raise OKConfigError('Cannot authenticate') result = helper_functions.runCommand("%s/install_nsclient.sh '%s' --domain '%s' --user '%s' --password '%s'" % (config.nsclient_installfiles,remote_host,domain,username,password)) return result
def pingscan(network='192.168.1.0/24'): """scans a specific network, returns a list of all ip that respond""" command = "fping -t 50 -i 10 -a " if network.find('/') > 0: command += " -g " command += network r,stdout,stderr = runCommand(command) if r > 1: raise Exception("Error running %s: %s" % (command,stderr) ) ip_list = [] for i in stdout.split('\n'): try: socket.inet_aton(i) except Exception: continue ip_list.append(i) return ip_list
def pingscan(network='192.168.1.0/24'): """scans a specific network, returns a list of all ip that respond""" command = "fping -t 50 -i 10 -a " if network.find('/') > 0: command += " -g " command += network r, stdout, stderr = runCommand(command) if r > 1: raise Exception("Error running %s: %s" % (command, stderr)) ip_list = [] for i in stdout.split('\n'): try: socket.inet_aton(i) except Exception: continue ip_list.append(i) return ip_list
def traceroute(host="localhost"): """ Returns a list of every host discovered while tracerouting Returns: ["ip1","ip2","ip3",...] """ result = [] returncode,stdout,stderr = runCommand("traceroute -n '%s'" % host) print stdout if returncode > 0: raise okconfig.OKConfigError("Failed to traceroute host %s, error: %s" % (host, stderr)) for line in stdout.split("\n"): line = line.split() if len(line) < 2: continue if line[0].isdigit(): result.append(line[1]) return result
def traceroute(host="localhost"): """ Returns a list of every host discovered while tracerouting Returns: ["ip1","ip2","ip3",...] """ result = [] returncode, stdout, stderr = runCommand("traceroute -n '%s'" % host) print stdout if returncode > 0: raise okconfig.OKConfigError( "Failed to traceroute host %s, error: %s" % (host, stderr)) for line in stdout.split("\n"): line = line.split() if len(line) < 2: continue if line[0].isdigit(): result.append(line[1]) return result
def is_agent_okconfig(self): """returns true if host responds to check_nrpe commands""" returncode,stdout,stderr = runCommand("check_nrpe -H '%s' -c get_disks") if returncode == 0: return True if returncode == 1: return False return None