[rules-dev] doubt in the rules

hare ram hare.bond at gmail.com
Thu Jul 12 15:47:23 EDT 2007


Hello everyone,

The rules I wrote are


rule "Test 1 Rule"
    salience 1000
    when
        Line ( $admin : line)
        eval ( $admin.matches("^.*@\\S*[#>]\\s*show\\s+interface[s]*\\s*$"))
        Line ( $lineSecond : line)
        eval (
$lineSecond.matches("^\\s*(\\S+)\\s+is\\s+(up|down|administratively
down),\\s*line\\s+protocol\\s+is\\s+(up|down)\\s*$"))
        device : Device()
    then
        System.out.println("********************************************");
        device.setVendorType("Foundry");

end

rule "Juniper Show Interface CanIParse() Rule"
    salience 5000

    when
        Line ( $regex : line)
        eval ( $regex.matches("^.*@\\S*[#>]\\s*show\\s+interface[s]*\\s*$"))
        Line ( $lineStr : line)
        eval (
$lineStr.matches("^.*\\s*Physical\\s+interface:\\s*([^,\\s]+),\\s+([^,]+),.*$"))

        device : Device()
    then
        System.out.println
("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        device.setVendorType("Juniper");
end


Basically the rules are searching for two regular expressions, of which one
is same for the both of the rules.But when i write the rules like the above
I do not get the correct o/p, but however if i change my rules to (bold) as
below, I get the correct output.So is it necessary the the declaration has
to be same if the both the rules have same regex

rule "Test 1 Rule"
    salience 1000
    when
        Line ( $regex : line)
        eval ( $regex.matches("^.*@\\S*[#>]\\s*show\\s+interface[s]*\\s*$"))
        Line ( $lineSecond : line)
        eval (
$lineSecond.matches("^\\s*(\\S+)\\s+is\\s+(up|down|administratively
down),\\s*line\\s+protocol\\s+is\\s+(up|down)\\s*$"))
        device : Device()
    then
        System.out.println("********************************************");
        device.setVendorType("Foundry");

end

rule "Juniper Show Interface CanIParse() Rule"
    salience 5000

    when
        Line ( $regex : line)
        eval ( $regex.matches("^.*@\\S*[#>]\\s*show\\s+interface[s]*\\s*$"))
        Line ( $lineStr : line)
        eval (
$lineStr.matches("^.*\\s*Physical\\s+interface:\\s*([^,\\s]+),\\s+([^,]+),.*$"))

        device : Device()
    then
        System.out.println
("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        device.setVendorType("Juniper");
end

Thanks
Shiva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20070712/1e0b910a/attachment.html 


More information about the rules-dev mailing list