[Nodebrain-users] Nagios integration and counting objects
Rule Engine for State and Event Monitoring
Brought to you by:
trettevik
From: Marco M. <ma...@mu...> - 2013-11-25 11:56:53
|
Hi fellow nodebrain users! I'd like to submit a solution for my problem that you can probably improve... Let's suppose to define a tree node to store the status of a resource (let's say apache) of some servers (the total number of servers is dynamic and unknown): define servers node tree; and then populate the tree (via some servant scripts): servers. assert ("srv1","apache")=0; # or alert servers("srv1","apache")=0 servers. assert ("srv2","apache")=0; servers. assert ("srv3","apache")=0; servers. assert ("srv4","apache")=0; we'll get: show servers "srv1" "apache"=0 "srv2" "apache"=0 "srv3" "apache"=0 "srv1" "apache"=0 The goal is to count the number of server with apache != 0 (ie. resource not available). The first thing I tried was: define broken node tree; # a tree that contains servers without running apache define r1 on(!servers(x,"apache")=0): broken(x); # very much like the tutorial (paragraph 6.3) which should trigger on assert x="srv1" and check the status and eventually define "srv1"=1, like this: servers. assert ("srv1","apache")=1; Rule local.r1 fired (@.local.broken(@.local.x)=1) show broken broken = ! == node tree "srv1"=1 To clear the state when apache is available again I can define another rule: define r2 on(servers(x,"apache")=0) ?broken(x); # or broken(x)=0 servers. assert ("srv1","apache")=0; Rule local.r2 fired (@.local.broken(@.local.x)=?) show broken broken = ! == node tree This works as far as x has the value of a server (i.e. to trigger those rules I have to assert x=). To me this doesn't sound as an elegant solution (and probably I should have used IF/ALERT instead of ON/ASSERT). Then there is the problem that I want to know how many server are broken and call an adapter. How can I count the cardinality of a tree (or the number of element with a given property/value directly on the servers tree)? With those questions in mind I started to thing that probably the method I'm following is not the best (also because it resembles too closely an standard programming logic): is there a better way? TIA — Dr. Marco Musso |