I have a file (let’s say ‘powerstatus’) that has only 2 values 0 or 1.
(This is just a script on another server that echo 0 or 1 into that file.)
Is there a way that I create an item ‘from’ this file?
Or what’s a good way?
The end goal is to update an item with the power status of servers. That I can use in rules, sitemaps…
And linked with this, send out messages, reboot/shutdown machines…
Hereby the convert rule, and the rule that’s been triggered by it:
rule "check powerstatus of Hypervisor"
//Convert textvalue 0 or 1 towards OH item ON or OFF.
when
Time cron "0 0/1 * * * ?"
then
Thread::sleep(10000) // Give other server some time
var String result = executeCommandLine("cat /diy/power_status",2000)
if (result == "0") {
HypervisorPower.postUpdate(OFF)
}
else if (result == "1") {
HypervisorPower.postUpdate(ON)
}
end
rule "Action for Hypervisor on power failure"
//Trigger action if power is lost
when
Item HypervisorPower changed from ON to OFF
then
<knip>
end
ps The thread of 10 sec is because the other server is also trigger every minute. This way, I’m sure that the other server is finished with his check. Else I would lose a whole minute, and with my small UPS…
So why not trigger the rule using `10 0/1 * * * ?" ? This is functionally equivalent to what you are doing only you won’t be tying up a runtime thread waiting for those ten seconds.