You are not logged in.

#1 2014-09-02 17:36:33

insane_alien
Member
Registered: 2007-11-19
Posts: 39

[solved] python monitoring script

Hi,

not really sure where to begin looking on this one. I have a python(3) script that i use to monitor about 50 sensor channels at work.

The script assigns a 'score' to each result based on some simple rules (eg if ChanA >10 and ChanB <5: score +=5 )

As this was a quick cobble, the rules are hardcoded into the script, is there anyway I can store rules in a config file so I can have different rulesets based on what i want to monitor? i don't fancy the idea of having 5, 10, 20 nearly identical scripts to maintain.

cheer,

Last edited by insane_alien (2014-09-06 21:22:36)

Offline

#2 2014-09-02 17:44:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [solved] python monitoring script

I think I'm missing something here.  There is not sufficient detail provided for anyone to help you implement this.  As is it's simply a yes/no question.  The answer is 'Yes' of course you can.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2014-09-02 17:44:30

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [solved] python monitoring script

Absolutely...look at configparser. You can so use argparse to target which sensor you want to monitor when you launch the script, then pull the configuration values from the config file with configparser.

Scott

Offline

#4 2014-09-02 18:00:06

insane_alien
Member
Registered: 2007-11-19
Posts: 39

Re: [solved] python monitoring script

okay, thats how i can store the configuration, i'm not sure on the details of taking the configuration and getting python to interpret that as a series of if statements.

so if i have in a config file the rules

ChanA > 5 and ChanB <10: +5
ChanC >6: -5

how can i present that to python that it takes it as an if statement?

Offline

#5 2014-09-03 03:16:32

Theta91
Member
Registered: 2014-08-21
Posts: 13

Re: [solved] python monitoring script

woops, totally misread, originally!

You'd have to implement some special parsing for the rules. You'd probably want to do more like:
ChanA > 5: something
ChanB < 10: something else
etc. in your config file.

Then you'd read in each part and parse it separately to construct your if statement (channel...condition...value). It may be easier to have some rules hardcoded in separate scripts than to do a very complicated config file / parsing system, though. It's really just hard to tell without more explicit information on the extent of your use case (how complicated do these conditions get?) and what you really need to accomplish.

Last edited by Theta91 (2014-09-03 03:26:19)

Offline

#6 2014-09-03 11:03:38

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [solved] python monitoring script

Depending on how many channels their are, each rule could be a pair of numbers for min and max for that channel.  So each rule would specify a range for every channel, and then an adjustment to a score.  Any channel for which that rule should not matter, just use the most extreme values - or perhaps an NA type value if possible.  So for 5 channels the config entries would have 11 values:

{5, 1000}, {-1000, 1000}, {-1000, 10}, {-1000, 1000}, {-1000, 1000}, 5
{-1000, 1000}, {-1000, 1000}, {6, 1000}, {-1000, 1000}, {-1000, 1000}, -5


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2014-09-03 17:36:54

insane_alien
Member
Registered: 2007-11-19
Posts: 39

Re: [solved] python monitoring script

that could work i never thought about using a mask type system to implement the rules. I'll give it a go and let you know how it goes.

Offline

#8 2014-09-06 21:23:35

insane_alien
Member
Registered: 2007-11-19
Posts: 39

Re: [solved] python monitoring script

yeah, that's working fine. i'll build a little user interface to allow everyone else to make rules.

Thanks.

Offline

Board footer

Powered by FluxBB