Exemplo n.º 1
0
    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'
Exemplo n.º 2
0
    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