There is a usability issue with pmie's grammar, that becomes
particularly obvious when you try to connect pmie to an active alerting
system like nagios.
In this use case, pmie needs to be able to
(a) emit a message to indicate an alert, else
(b) emit "OK" (or the moral equivalent)
Not emitting "OK" is not an option as the alerting subsystem consuming
the messages takes this to mean pmie has died (as opposed to the pmie
world view that silence is golden).
Historically this has been implemented with
crafty_boolean_expression -> print "alarm";
not (crafty_boolean_expression) -> print "OK";
which is clumsy and error prone.
It gets even messier for more than 2 states of output, e.g. "panic",
"alarm", "warning", "ok".
I've tried to see if I could twist the grammar to allow a disjunction of
rules, but we're already at the limit of LALR(1) grammars, and I just
don't have the strength or the skill to refactor the grammar to
correctly handle the ambiguities that a disjunction of rules introduces.
So instead I am proposed the coward's approach, namely a new keyword to
introduce a disjunction of rules and a new keyword to separate rules, e.g.
ruleset
rule1
else rule2
...
;
So the first example above becomes
ruleset
crafty_boolean_expression -> print "alarm"
else true -> print "ok";
For extra credit, the last alternative may be written as
else <action>
rather than
else <predicate -> <action>
when the associated <predicate> is "true" as above.
And the multistate example becomes
ruleset
extreme_predicate -> print "panic"
else bad_predicate -> print "alarm"
else unusual_predicate -> print "warning"
else print "OK";
I've done enough of the implementation to know this will work for the
parser and the execution engine without major disruption.
Of course "ruleset ... else ... ;" could be replaced by "if ... elif ...
elif ... else ...;" or any equivalent cosmetic change to the suggested
syntax.
Warm up the flame throwers ...
|