2014-03-27 51 views
0

任何幫助,請...我想監視Linux系統上的網絡接口,例如對於我已經建立2個規則和類的eth0,其監視inerfacesJBoss Drools 6計時器連續執行

rule "check eth0 down" 
timer (cron:0/5 * * * * ?) 
when  
$device : IapDevice(operstateEth0 == "down") 
then   
System.out.println("interface eth0 is down"); 
update($device);  
end 

rule "check eth0 up" 
timer (cron:0/5 * * * * ?) 
when  
$device : IapDevice(operstateEth0 == "up") 
then   
System.out.println("interface eth0 is up"); 
update($device);  
end 

主要的Java類看起來像

kSession.insert(new IapDevice()); 
new Thread(new Runnable() 
{  
public void run() 
{   
    kSession.fireUntilHalt();   
}  
}).start(); 

IapDevice

public class IapDevice 
{   
    public String getOperstateEth0() 
    { 
    return IfaceUtils.operstateEth0(); 
    }   
} 

這種設置檢測的狀態的變化接口,但是當它執行時,它會連續輸出System.out.print(),而不是每5秒一次。 我試着在規則中加入[no-loop true],但是它不檢測它是否從down狀態恢復......如何解決這個問題?

問候, Rihards

回答

0

三個規則:

rule "check eth0 down" // up 
when  
    $device : IapDevice(operstateEth0 == "down") // "up" 
then   
    System.out.println("interface eth0 is down"); // up 
end 

rule "trigger" 
timer (cron:0/5 * * * * ?) 
when  
    $device : IapDevice() 
then 
    update($device);  
end 

定時器功能文檔比較粗略。必須做更多的工作才能輸出狀態更改:保持另一個對象註冊最後一個狀態,然後進行比較。

rule "check eth0 up/down" 
when 
    $state: IapState($lastState: operstateEth0) 
    $device : IapDevice($newState: operstateEth0 != $lastState) 
then 
    modify($state){ setOperstateEthh0($newState) } 
end