Beispiel #1
0
    def load(self, tdef):

        trig = Trigger(self.view, tdef)

        # Make sure the query parses
        storm = trig.tdef['storm']
        self.view.core.getStormQuery(storm)

        cond = trig.tdef.get('cond')
        tag = trig.tdef.get('tag')
        form = trig.tdef.get('form')
        prop = trig.tdef.get('prop')

        if cond not in Conditions:
            raise s_exc.NoSuchCond(name=cond)

        if cond in ('node:add', 'node:del') and form is None:
            raise s_exc.BadOptValu(
                mesg='form must be present for node:add or node:del')
        if cond in ('node:add', 'node:del') and tag is not None:
            raise s_exc.BadOptValu(
                mesg='tag must not be present for node:add or node:del')
        if cond in ('tag:add', 'tag:del'):
            if tag is None:
                raise s_exc.BadOptValu(mesg='missing tag')
            s_chop.validateTagMatch(tag)
        if prop is not None and cond != 'prop:set':
            raise s_exc.BadOptValu(mesg='prop parameter invalid')

        if cond == 'node:add':
            self.nodeadd[form].append(trig)

        elif cond == 'node:del':
            self.nodedel[form].append(trig)

        elif cond == 'prop:set':
            if prop is None:
                raise s_exc.BadOptValu(mesg='missing prop parameter')
            if form is not None or tag is not None:
                raise s_exc.BadOptValu(
                    mesg='form and tag must not be present for prop:set')
            self.propset[prop].append(trig)

        elif cond == 'tag:add':

            if '*' not in tag:
                self.tagadd[(form, tag)].append(trig)
            else:
                # we have a glob add
                self.tagaddglobs[form].add(tag, trig)

        elif cond == 'tag:del':

            if '*' not in tag:
                self.tagdel[(form, tag)].append(trig)
            else:
                self.tagdelglobs[form].add(tag, trig)

        self.triggers[trig.iden] = trig
        return trig
Beispiel #2
0
    def __post_init__(self, iden, triggers):

        self.iden = iden
        self.triggers = triggers

        if self.ver != 1:
            raise s_exc.BadOptValu(mesg='Unexpected rule version')
        if self.cond not in Conditions:
            raise s_exc.BadOptValu(mesg='Invalid trigger condition')
        if self.cond in ('node:add', 'node:del') and self.form is None:
            raise s_exc.BadOptValu(
                mesg='form must be present for node:add or node:del')
        if self.cond in ('node:add', 'node:del') and self.tag is not None:
            raise s_exc.BadOptValu(
                mesg='tag must not be present for node:add or node:del')
        if self.cond == 'prop:set' and (self.form is not None
                                        or self.tag is not None):
            raise s_exc.BadOptValu(
                mesg='form and tag must not be present for prop:set')
        if self.cond in ('tag:add', 'tag:del'):
            if self.tag is None:
                raise s_exc.BadOptValu(mesg='missing tag')
            s_chop.validateTagMatch(self.tag)
        if self.prop is not None and self.cond != 'prop:set':
            raise s_exc.BadOptValu(mesg='prop parameter invalid')
        if self.cond == 'prop:set' and self.prop is None:
            raise s_exc.BadOptValu(mesg='missing prop parameter')
Beispiel #3
0
 def __post_init__(self):
     if self.ver != 1:
         raise s_exc.BadOptValu(mesg='Unexpected rule version')
     if self.cond not in Conditions:
         raise s_exc.BadOptValu(mesg='Invalid trigger condition')
     if self.cond in ('node:add', 'node:del') and self.form is None:
         raise s_exc.BadOptValu(mesg='form must be present for node:add or node:del')
     if self.cond in ('node:add', 'node:del') and self.tag is not None:
         raise s_exc.BadOptValu(mesg='tag must not be present for node:add or node:del')
     if self.cond == 'prop:set' and (self.form is not None or self.tag is not None):
         raise s_exc.BadOptValu(mesg='form and tag must not be present for prop:set')
     if self.cond in ('tag:add', 'tag:del'):
         if self.tag is None:
             raise s_exc.BadOptValu(mesg='missing tag')
         s_chop.validateTagMatch(self.tag)
     if self.prop is not None and self.cond != 'prop:set':
         raise s_exc.BadOptValu(mesg='prop parameter invalid')
     if self.cond == 'prop:set' and self.prop is None:
         raise s_exc.BadOptValu(mesg='missing prop parameter')
Beispiel #4
0
 def test_chop_validatetagmatch(self):
     self.raises(s_exc.BadTag, s_chop.validateTagMatch, ' foo')
     self.raises(s_exc.BadTag, s_chop.validateTagMatch, 'foo&bar')
     self.raises(s_exc.BadTag, s_chop.validateTagMatch, 'foo..bar')
     self.none(s_chop.validateTagMatch('foo.*.bar'))
     self.none(s_chop.validateTagMatch('**foo.*.bar'))
Beispiel #5
0
 def test_chop_validatetagmatch(self):
     self.raises(s_exc.BadTag, s_chop.validateTagMatch, ' foo')
     self.raises(s_exc.BadTag, s_chop.validateTagMatch, 'foo&bar')
     self.raises(s_exc.BadTag, s_chop.validateTagMatch, 'foo..bar')
     self.none(s_chop.validateTagMatch('foo.*.bar'))
     self.none(s_chop.validateTagMatch('**foo.*.bar'))