请帮助...我想监控linux系统上的网络接口,例如eth0为此我创建了2个监控inerfaces的规则和类
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 :(得分: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