Beispiel #1
0
    def tokenparser(self, toklist, toktypes, indent):
        super(COM, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.cmd
        except AttributeError:
            raise directive.ParseFailure("Command (cmd) not specified")
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        # Set any COM-specific variables
        #  cmd = the command
        self.defaultVarDict['cmd'] = self.args.cmd

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.COM.%s.%s' % (log.hostname, self.args.cmd,
                                        self.args.rule)
        self.state.ID = self.ID

        log.log("<directive>COM.tokenparser(): ID '%s' cmd '%s' rule '%s'" %
                (self.state.ID, self.args.cmd, self.args.rule), 8)
Beispiel #2
0
    def tokenparser(self, toklist, toktypes, indent):
        """
        Parse directive arguments.
        """

        super(STORE, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        # Rule should be a string
        if not isinstance(self.args.rule, str):
            raise directive.ParseFailure("STORE parse error, rule is not string.")

        self.defaultVarDict['rule'] = self.args.rule

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.STORE.%s' % (log.hostname, self.args.rule)
        self.state.ID = self.ID

        log.log("<directive>STORE.tokenparser(): ID '%s' rule '%s'" %
                (self.state.ID, self.args.rule), 8)
Beispiel #3
0
    def tokenparser(self, toklist, toktypes, indent):
        """
        Parse directive arguments.
        """

        super(FS, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.fs
        except AttributeError:
            raise directive.ParseFailure("Filesystem not specified")
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        # Set any directive-specific variables
        self.defaultVarDict['rule'] = self.args.rule

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.FS.%s' % (log.hostname, self.args.fs)
        self.state.ID = self.ID

        log.log("<directive>FS.tokenparser(): ID '%s' fs '%s' rule '%s'" %
                (self.state.ID, self.args.fs, self.args.rule), 8)
Beispiel #4
0
    def tokenparser(self, toklist, toktypes, indent):
        """Parse tokenized input."""

        super(PROC, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.name
        except AttributeError:
            raise directive.ParseFailure("Process name not specified")
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        # Set any PROC-specific action variables
        #  proc_check_name = the process name being checked
        self.defaultVarDict['name'] = self.args.name

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.PROC.%s' % (log.hostname, self.args.name)
        self.state.ID = self.ID

        log.log("<directive>PROC.tokenparser(): ID '%s' name '%s' rule '%s'" %
                (self.state.ID, self.args.name, self.args.rule), 8)
Beispiel #5
0
    def tokenparser(self, toklist, toktypes, indent):
        """Parse directive arguments."""
        super(RPI, self).tokenparser(toklist, toktypes, indent)

        try:
            self.args.sensor
        except AttributeError:
            raise directive.ParseFailure('Sensor not specified')
        try:
            self.args.sensortype
        except AttributeError:
            raise directive.ParseFailure('Sensor type not specified')
        if self.args.sensor == 'DHT':
            try:
                self.args.gpiopin
                self.defaultVarDict['gpiopin'] = self.args.sensor
            except AttributeError:
                raise directive.ParseFailure('GPIO pin not specified')
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure('Rule not specified')

        self.defaultVarDict['sensor'] = self.args.sensor
        self.defaultVarDict['sensortype'] = self.args.sensortype
        self.defaultVarDict['rule'] = self.args.rule

        # define unique ID
        if self.ID is None:
            self.ID = '%s.RPI.%s' % (log.hostname, self.args.sensor)
        self.state.ID = self.ID

        log.log(
            "<disk>RPI.tokenparser(): ID '%s' sensor '%s' rule '%s'" %
            (self.state.ID, self.args.sensor, self.args.rule), 8)
Beispiel #6
0
    def tokenparser(self, toklist, toktypes, indent):
        super(PORT, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.host
        except AttributeError:
            raise directive.ParseFailure("Host not specified")
        try:
            self.args.port
        except AttributeError:
            raise directive.ParseFailure("Port not specified")
        try:
            self.args.port = int(self.args.port)
        except ValueError:
            raise directive.ParseFailure("Port is not an integer: %s" %
                                         (self.args.port))
        # send is optional
        try:
            self.args.send
        except AttributeError:
            self.args.send = ""                # default to not send
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        # Set any PORT-specific variables
        #  host = the host
        #  port = the port
        #  send = the send string
        #  expect = the expect string
        self.defaultVarDict['host'] = self.args.host
        self.defaultVarDict['port'] = self.args.port
        self.defaultVarDict['rule'] = self.args.rule
        self.defaultVarDict['send'] = self.args.send
        if 'expect' in dir(self.args):
            self.defaultVarDict['expect'] = self.args.expect

        if 'expectrexp' in dir(self.args):
            self.defaultVarDict['expectrexp'] = self.args.expectrexp
            self.regexp = re.compile(self.args.expectrexp)

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.PORT.%s.%d' % (log.hostname,
                                         self.args.host, self.args.port)
        self.state.ID = self.ID

        log.log("<directive>PORT.tokenparser(): ID '%s' host '%s' port %d" %
                (self.state.ID, self.args.host, self.args.port), 8)
Beispiel #7
0
    def tokenparser(self, toklist, toktypes, indent):
        super(SP, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.port
        except AttributeError:
            raise directive.ParseFailure("Port not specified")
        try:
            self.args.protocol
        except AttributeError:
            raise directive.ParseFailure("Protocol not specified")
        try:
            self.args.bindaddr
        except AttributeError:
            raise directive.ParseFailure("Bind address not specified")
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        if self.args.bindaddr == '*':
            self.args.bindaddr = '0.0.0.0'

        self.port_n = self.args.port                # remember port name

        # lets try resolving this service port to a number
        try:
            self.port = socket.getservbyname(str(self.port_n), self.args.protocol)
        except socket.error:
            self.port = self.port_n

        self.defaultVarDict['port'] = self.port_n
        self.defaultVarDict['bindaddr'] = self.args.bindaddr
        self.defaultVarDict['protocol'] = self.args.protocol

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.SP.%s/%s.%s' % (log.hostname, self.args.protocol,
                                          self.port_n, self.args.bindaddr)
        self.state.ID = self.ID

        log.log("<directive>SP.tokenparser(): ID '%s' protocol '%s', port '%s', bind addr '%s'" %
                (self.state.ID, self.args.protocol,
                 self.port, self.args.bindaddr), 8)
Beispiel #8
0
    def tokenparser(self, toklist, toktypes, indent):
        """Parse rest of rule (after ':')."""
        super(IF, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.name
        except AttributeError:
            raise directive.ParseFailure("Interface name not specified")
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        self.defaultVarDict['name'] = self.args.name

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.IF.%s.%s' % (log.hostname,self.args.name,self.rule)
        self.state.ID = self.ID

        log.log("<directive>IF.tokenparser(): ID '%s' name '%s', rule '%s'" %
                (self.state.ID, self.args.name, self.args.rule), 8)
Beispiel #9
0
    def tokenparser(self, toklist, toktypes, indent):
        super(PID, self).tokenparser(toklist, toktypes, indent)

        # test required arguments
        try:
            self.args.pidfile
        except AttributeError:
            raise directive.ParseFailure("pidfile argument not specified")
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure("Rule not specified")

        # Set any PID-specific variables
        #  %pidf = the PID-file
        self.defaultVarDict['pidfile'] = self.args.pidfile
        self.defaultVarDict['rule'] = self.args.rule

        # define the unique ID
        if self.ID is None:
            self.ID = '%s.PID.%s.%s' % (log.hostname,self.args.pidfile,self.args.rule)
        self.state.ID = self.ID

        log.log("<directive>PID.tokenparser(): ID '%s' pid '%s' rule '%s'" % (self.state.ID, self.args.pidfile, self.args.rule), 8)
Beispiel #10
0
    def tokenparser(self, toklist, toktypes, indent):
        """Parse directive arguments."""
        super(DISK, self).tokenparser(toklist, toktypes, indent)

        try:
            self.args.device
        except AttributeError:
            raise directive.ParseFailure('Device not specified')
        try:
            self.args.rule
        except AttributeError:
            raise directive.ParseFailure('Rule not specified')

        self.defaultVarDict['device'] = self.args.device
        self.defaultVarDict['rule'] = self.args.rule

        # define unique ID
        if self.ID is None:
            self.ID = '%s.DISK.%s' % (log.hostname, self.args.device)
        self.state.ID = self.ID

        log.log(
            "<disk>DISK.tokenparser(): ID '%s' device '%s' rule '%s'" %
            (self.state.ID, self.args.device, self.args.rule), 8)