Rule to count open windows

When using Contact Items, the Group has to be of type Contact, too:

Group:Contact:OR(OPEN,CLOSED) MyWindows "open Windows [%d]" <window>
Contact Window1 "Window 1 [%s]" (MyWindows) {...}
Contact Window2 "Window 2 [%s]" (MyWindows) {...}
Contact Window3 "Window 3 [%s]" (MyWindows) {...}
Contact Window4 "Window 4 [%s]" (MyWindows) {...}
Contact Window5 "Window 5 [%s]" (MyWindows) {...}

Now, when using

Text item=MyWindows

in sitemap, you should get always the correct information.

If you explicitly want to count them in a rule…

rule "count openwindows"
when
    Member of MyWindows changed
then
    val Number openWindows = MyWindows.members.filter[w|w.state == OPEN].size
    val Number unknownWindows = MyWindows.members.filter[w|w.state == NULL].size
    val Number closedWindows = MyWindows.members.filter[w|w.state == CLOSED].size
    logInfo("window","state for Windows: open: {} closed: {} unknown: {}",openWindows,closedWindows,unknownWindows)
end
1 Like