diff --git a/linspector b/linspector index 2eb01db..4a9d4f9 100755 --- a/linspector +++ b/linspector @@ -1,6 +1,7 @@ #!/usr/bin/python2.7 -tt __version__ = "0.4/TETRIS" +__default_config__ = "./linspector.json" import argparse import time @@ -11,8 +12,6 @@ from lib.core.logger import Logger from lib.config.config import Config from apscheduler.scheduler import Scheduler -DEFAULT_CONFIG = "./linspector.minimal.json" - def parseArgs(): parser = argparse.ArgumentParser( @@ -23,7 +22,7 @@ def parseArgs(): parser.add_argument("action", choices=["start", "stop", "restart", "attach"], help="defines if linspector should beeing attached, started, stopped or restarted.") parser.add_argument("--version", action="version", version="%(prog)s " + str(__version__)) - parser.add_argument("-c", "--config", default=DEFAULT_CONFIG, + parser.add_argument("-c", "--config", default=__default_config__, help="select configfile to use") parser.add_argument("-l", "--logfile", default="./log/linspector.log", metavar="FILE", help="set logfile to use") diff --git a/linspector.json b/linspector.json index 82ceb0c..2031f78 100644 --- a/linspector.json +++ b/linspector.json @@ -1,230 +1,142 @@ { - "services": - { - "discusage": {"command": "ssh @host df -a @device", "parser": "df"}, - "load": {"command": "ssh @host uptime"}, - "dirsize": { "command": "ssh @host du -chs @path"}, - "filesize": {"command": "ssh @host du -chs @path"}, - "loggedinusercount": {"command": "ssh @host who | wc -l"}, - "loggedinusers": {"command": "ssh @host who"}, - "swapusage": {"command": "ssh @host cat /proc/swaps"}, - "processcount": {"command": "ssh @host ps ax | wc -l"}, - "processcountbyname": {"command": "ssh @host ps ax | grep @name | wc -l"}, - "fileage": {"command": "ssh @host ls -l @file"}, - "ping": {"command": "ping @host"}, - "snmpget": {"command": "snmpget -v1 -c public $oid"}, - "busy_waiting": {"command": "sleep 3600"}, - "htmlcontent": {"command": "wget -qO- @url", "comment": "Get HTML Content for a string lookup."} - }, - "filters": - { - "email": - { - "command": "/usr/bin/warn_the_admin_mail @member @+message", - "comment": "Sends an E-Mail to the member.", - "priority": 1 - }, - "sms": - { - "command": "/usr/bin/warn_the_admin_sms @member @+message", - "comment": "Sends a Short Message to the member.", - "priority": 0 - }, - "foo": - { - "command": "/usr/bin/warn_the_admin_foo @member @+message", - "priority": 500 - }, - "mongowriter": - { - "command": "./plugins/mongowriter.py @+message localhost 27017 linspector123", - "priority": 1000 + "filters":{ + "email":{ + "command":"email @member @+message", + "comment":"Sends an E-Mail to the member.", + "priority":1 } }, - "members": - { - "hanez": - { - "name": "Johannes Findeisen", - "comment": "Just a nerd doing admin stuff...", - "parent": "admin", - "filters": - { - "email": "you@hanez.org", - "sms": "+23345567" - } + "members":{ + "hanez":{ + "name":"Johannes Findeisen", + "comment":"Just a nerd doing admin stuff...", + "parent": "darth", + "filters":{ "email":"you@hanez.org" } }, - "linspector": - { - "name": "Linspector BOT", - "comment": "Botty Botsen...", - "parent": "admin", - "filters": - { - "email": "botty@hanez.org", - "sms": "+23345567213123" - } - }, - "unixpeople": - { - "name": "Hanna Findeisen", - "comment": "Master of UNIX", - "parent": "admin", - "filters": - { - "email": "master@hanez.org", - "sms": "+2334556733333" - } - }, - "admin": - { - "name": "Peter Hansen", - "comment": "The son of Hans-Peter Hansen", - "parent": "ultraadmin", - "filters": - { - "email": "admin@systemchaos.org", - "sms": "+23345567", - "phone": "+435345345" - } - }, - "ultraadmin": - { - "name": "Hans-Peter Hansen (CEO)", - "comment": "The guru of the Datacenter", - "parent": "darthvader", - "filters": - { - "email": "bofh@systemchaos.org", - "sms": "+23345567", - "phone": "+435345345" - } - }, - "darthvader": - { - "name": "Darth Vader", - "comment": "The Father", - "filters": - { - "email": "darth.vader@systemchaos.org" - } - }, - "jens": - { - "name": "Jens Larssen", - "comment": "Our network guru", - "filters": - { - "email": "jens@systemchaos.org", - "sms": "+23345567", - "phone": "+435345345" - } - }, - "ruff": - { - "name": "Ruffn Buffn", - "filters": - { - "sms": "+23343457" - } - }, - "mongowriter": - { - "name": "MongoDB Database writer plugin", - "filters": - { - "mongowriter": "localhost" - } + "darth":{ + "name":"Darth Vader", + "comment":"The father", + "filters":{ "email":"darth.vader@hanez.org" } } }, - "periods": - { - "twentyfourseven": - { - "year": "*", - "month": "*", - "day": "*", - "week": "*", - "hour": "*", - "minute": "*/1", - "second": "0", - "comment": "Cron Job / Every minute" + "periods":{ + "short":{ + "seconds":5, + "comment":"Interval job; every 10 seconds" }, - "do_every_x_times" : { - "days": 0, - "weeks": 0, - "hours": 0, - "minutes": 0, - "seconds": 10, - "comment": "Interval Job / Every 10 seconds" + "middle":{ + "seconds":60, + "comment":"Interval job; every 60 seconds" }, - "next_christmas" : { - "date": "2013-12-24 20:00:00", - "comment": "Date Job / Just one day" + "long":{ + "minutes":2, + "comment":"Interval job; every 2 minutes" } }, - "hosts": - { - "hanez": - { - "host": "www.hanez.org", - "services": - { - "discusage": - [ - { "device": "/dev/sda1", "warning": "80%", "critical": "90%" }, - { "device": "/dev/sda2", "warning": "70%", "critical": "90%" }, - { "device": "/dev/sda3", "warning": "70GB", "critical": "90GB" } - ], - "load": - [ - { "warning": 8.00, "critical": 12.00 } - ], - "dirsize": - [ - { "path": "/var/log", "warning": 30000000, "critical": 40000000 } - ], - "processcount": - [ - { "warning": 3000, "critical": 3800 } - ], - "processcountbyname": - [ - { "name": "java", "warning": 100, "critical": 200 } - ], - "fileage": - [ - { "file": "/var/backup/server_1", "warning": 2, "critical": 3 } - ], - "htmlcontent": - [ - { "url": "@host/test.php", "content": "

Server up!

" } - ], - "ping": - [ - {} - ] - } + "hostgroups":{ + "group1":{ + "members":[ "hanez" ], + "hosts":[ "a.systemchaos.org", "b.systemchaos.org" ], + "parents": [ "network" ], + "services":[ + { + "class":"ping", + "fails":{ "warning":"100ms", "critical":"150ms" }, + "periods": ["short"], + "threshold":10, + "parser":{ "class":"shell", "line":2, "col":5 } + }, + { + "class":"tcpconnect", + "args":{ "port":80 }, + "periods": ["middle"], + "threshold":2 + }, + { + "class":"tcpconnect", + "args":{ "port":25 }, + "periods":["long"], + "threshold":2 + }, + { + "class":"tcpconnect", + "args":{ "port":110 }, + "periods": ["long"], + "threshold":2 + }, + { + "class":"http", + "args":{ "port": 80, "path": "/status.cgi", "method": "get", "params": { "foo": 1, "bar": 2 }, "protocol": "https"}, + "periods": ["long"], + "threshold":2, + "parser":{ "class":"grep", "string": "

I am up!

" }, + "comment": "Just a string grep" + } + ] + }, + "group2":{ + "members":["hanez"], + "hosts":["x.systemchaos.org", "y.systemchaos.org"], + "services":[ + { + "class":"ping", + "fails":{ "warning":"100ms", "critical":"150ms" }, + "periods":["short"], + "threshold":10, + "parser":{ "class":"shell", "line":2, "col":5 } + }, + { + "class":"tcpconnect", + "args":{ "port":2342 }, + "periods":["long"], + "threshold":2 + } + ] + }, + "group3":{ + "members":[ "hanez" ], + "hosts":[ "master.systemchaos.org" ], + "services":[ + { + "class":"ssh", + "args":{ "port": 23, "command": "df", "username": "hanez", "password": "secret", "key": "~/.ssh/id_rsa" }, + "fails":{ "warning":"80%", "critical":"90%" }, + "periods":[ "long" ], + "threshold":10, + "parser": [{ "class":"grep", "line": "/dev/sda1", "col":5 }, + [{ "class":"grep", "line": "/dev/sda2", "col":5 }, { "class":"grep", "line": "/dev/sda2", "col":5 }]] + } + ] + }, + "network":{ + "members":[ "hanez" ], + "hosts":[ "router.systemchaos.org" ], + "services":[ + { + "class":"ping", + "fails":{ "warning":"100ms", "critical":"150ms" }, + "periods": ["short"], + "threshold":10, + "parser":{ "class":"shell", "line":2, "col":5 } + } + ] } }, - "hostgroups": - { - "all": - { - "members": ["admin"], - "hosts": ["hanez"], - "parent": "network", - "threshold": 10, - "services": - { - "ping": ["do_every_x_times"] - } + "layouts":{ + "production":{ + "hostgroups": [ "group1" ], + "enabled": true + }, + "critical":{ + "hostgroups": [ "group3" ], + "enabled": false + }, + "all":{ + "hostgroups": [ "group1", "group2", "group3" ], + "enabled": false } }, - "layouts": {"production": {"hostgroups": ["all", "hanez", "network"], "enabled": true}, - "lazy": {"hostgroups": ["hanez", "ruff"], "enabled": false} - }, - "core": { + "core":{ "max_logfile_size": 1024000, "max_logfile_count": 4, "max_worker_threads": 8 diff --git a/linspector.minimal.NG.json b/linspector.minimal.NG.json deleted file mode 100644 index 2031f78..0000000 --- a/linspector.minimal.NG.json +++ /dev/null @@ -1,144 +0,0 @@ -{ - "filters":{ - "email":{ - "command":"email @member @+message", - "comment":"Sends an E-Mail to the member.", - "priority":1 - } - }, - "members":{ - "hanez":{ - "name":"Johannes Findeisen", - "comment":"Just a nerd doing admin stuff...", - "parent": "darth", - "filters":{ "email":"you@hanez.org" } - }, - "darth":{ - "name":"Darth Vader", - "comment":"The father", - "filters":{ "email":"darth.vader@hanez.org" } - } - }, - "periods":{ - "short":{ - "seconds":5, - "comment":"Interval job; every 10 seconds" - }, - "middle":{ - "seconds":60, - "comment":"Interval job; every 60 seconds" - }, - "long":{ - "minutes":2, - "comment":"Interval job; every 2 minutes" - } - }, - "hostgroups":{ - "group1":{ - "members":[ "hanez" ], - "hosts":[ "a.systemchaos.org", "b.systemchaos.org" ], - "parents": [ "network" ], - "services":[ - { - "class":"ping", - "fails":{ "warning":"100ms", "critical":"150ms" }, - "periods": ["short"], - "threshold":10, - "parser":{ "class":"shell", "line":2, "col":5 } - }, - { - "class":"tcpconnect", - "args":{ "port":80 }, - "periods": ["middle"], - "threshold":2 - }, - { - "class":"tcpconnect", - "args":{ "port":25 }, - "periods":["long"], - "threshold":2 - }, - { - "class":"tcpconnect", - "args":{ "port":110 }, - "periods": ["long"], - "threshold":2 - }, - { - "class":"http", - "args":{ "port": 80, "path": "/status.cgi", "method": "get", "params": { "foo": 1, "bar": 2 }, "protocol": "https"}, - "periods": ["long"], - "threshold":2, - "parser":{ "class":"grep", "string": "

I am up!

" }, - "comment": "Just a string grep" - } - ] - }, - "group2":{ - "members":["hanez"], - "hosts":["x.systemchaos.org", "y.systemchaos.org"], - "services":[ - { - "class":"ping", - "fails":{ "warning":"100ms", "critical":"150ms" }, - "periods":["short"], - "threshold":10, - "parser":{ "class":"shell", "line":2, "col":5 } - }, - { - "class":"tcpconnect", - "args":{ "port":2342 }, - "periods":["long"], - "threshold":2 - } - ] - }, - "group3":{ - "members":[ "hanez" ], - "hosts":[ "master.systemchaos.org" ], - "services":[ - { - "class":"ssh", - "args":{ "port": 23, "command": "df", "username": "hanez", "password": "secret", "key": "~/.ssh/id_rsa" }, - "fails":{ "warning":"80%", "critical":"90%" }, - "periods":[ "long" ], - "threshold":10, - "parser": [{ "class":"grep", "line": "/dev/sda1", "col":5 }, - [{ "class":"grep", "line": "/dev/sda2", "col":5 }, { "class":"grep", "line": "/dev/sda2", "col":5 }]] - } - ] - }, - "network":{ - "members":[ "hanez" ], - "hosts":[ "router.systemchaos.org" ], - "services":[ - { - "class":"ping", - "fails":{ "warning":"100ms", "critical":"150ms" }, - "periods": ["short"], - "threshold":10, - "parser":{ "class":"shell", "line":2, "col":5 } - } - ] - } - }, - "layouts":{ - "production":{ - "hostgroups": [ "group1" ], - "enabled": true - }, - "critical":{ - "hostgroups": [ "group3" ], - "enabled": false - }, - "all":{ - "hostgroups": [ "group1", "group2", "group3" ], - "enabled": false - } - }, - "core":{ - "max_logfile_size": 1024000, - "max_logfile_count": 4, - "max_worker_threads": 8 - } -} diff --git a/linspector.old.json b/linspector.old.json new file mode 100644 index 0000000..82ceb0c --- /dev/null +++ b/linspector.old.json @@ -0,0 +1,232 @@ +{ + "services": + { + "discusage": {"command": "ssh @host df -a @device", "parser": "df"}, + "load": {"command": "ssh @host uptime"}, + "dirsize": { "command": "ssh @host du -chs @path"}, + "filesize": {"command": "ssh @host du -chs @path"}, + "loggedinusercount": {"command": "ssh @host who | wc -l"}, + "loggedinusers": {"command": "ssh @host who"}, + "swapusage": {"command": "ssh @host cat /proc/swaps"}, + "processcount": {"command": "ssh @host ps ax | wc -l"}, + "processcountbyname": {"command": "ssh @host ps ax | grep @name | wc -l"}, + "fileage": {"command": "ssh @host ls -l @file"}, + "ping": {"command": "ping @host"}, + "snmpget": {"command": "snmpget -v1 -c public $oid"}, + "busy_waiting": {"command": "sleep 3600"}, + "htmlcontent": {"command": "wget -qO- @url", "comment": "Get HTML Content for a string lookup."} + }, + "filters": + { + "email": + { + "command": "/usr/bin/warn_the_admin_mail @member @+message", + "comment": "Sends an E-Mail to the member.", + "priority": 1 + }, + "sms": + { + "command": "/usr/bin/warn_the_admin_sms @member @+message", + "comment": "Sends a Short Message to the member.", + "priority": 0 + }, + "foo": + { + "command": "/usr/bin/warn_the_admin_foo @member @+message", + "priority": 500 + }, + "mongowriter": + { + "command": "./plugins/mongowriter.py @+message localhost 27017 linspector123", + "priority": 1000 + } + }, + "members": + { + "hanez": + { + "name": "Johannes Findeisen", + "comment": "Just a nerd doing admin stuff...", + "parent": "admin", + "filters": + { + "email": "you@hanez.org", + "sms": "+23345567" + } + }, + "linspector": + { + "name": "Linspector BOT", + "comment": "Botty Botsen...", + "parent": "admin", + "filters": + { + "email": "botty@hanez.org", + "sms": "+23345567213123" + } + }, + "unixpeople": + { + "name": "Hanna Findeisen", + "comment": "Master of UNIX", + "parent": "admin", + "filters": + { + "email": "master@hanez.org", + "sms": "+2334556733333" + } + }, + "admin": + { + "name": "Peter Hansen", + "comment": "The son of Hans-Peter Hansen", + "parent": "ultraadmin", + "filters": + { + "email": "admin@systemchaos.org", + "sms": "+23345567", + "phone": "+435345345" + } + }, + "ultraadmin": + { + "name": "Hans-Peter Hansen (CEO)", + "comment": "The guru of the Datacenter", + "parent": "darthvader", + "filters": + { + "email": "bofh@systemchaos.org", + "sms": "+23345567", + "phone": "+435345345" + } + }, + "darthvader": + { + "name": "Darth Vader", + "comment": "The Father", + "filters": + { + "email": "darth.vader@systemchaos.org" + } + }, + "jens": + { + "name": "Jens Larssen", + "comment": "Our network guru", + "filters": + { + "email": "jens@systemchaos.org", + "sms": "+23345567", + "phone": "+435345345" + } + }, + "ruff": + { + "name": "Ruffn Buffn", + "filters": + { + "sms": "+23343457" + } + }, + "mongowriter": + { + "name": "MongoDB Database writer plugin", + "filters": + { + "mongowriter": "localhost" + } + } + }, + "periods": + { + "twentyfourseven": + { + "year": "*", + "month": "*", + "day": "*", + "week": "*", + "hour": "*", + "minute": "*/1", + "second": "0", + "comment": "Cron Job / Every minute" + }, + "do_every_x_times" : { + "days": 0, + "weeks": 0, + "hours": 0, + "minutes": 0, + "seconds": 10, + "comment": "Interval Job / Every 10 seconds" + }, + "next_christmas" : { + "date": "2013-12-24 20:00:00", + "comment": "Date Job / Just one day" + } + }, + "hosts": + { + "hanez": + { + "host": "www.hanez.org", + "services": + { + "discusage": + [ + { "device": "/dev/sda1", "warning": "80%", "critical": "90%" }, + { "device": "/dev/sda2", "warning": "70%", "critical": "90%" }, + { "device": "/dev/sda3", "warning": "70GB", "critical": "90GB" } + ], + "load": + [ + { "warning": 8.00, "critical": 12.00 } + ], + "dirsize": + [ + { "path": "/var/log", "warning": 30000000, "critical": 40000000 } + ], + "processcount": + [ + { "warning": 3000, "critical": 3800 } + ], + "processcountbyname": + [ + { "name": "java", "warning": 100, "critical": 200 } + ], + "fileage": + [ + { "file": "/var/backup/server_1", "warning": 2, "critical": 3 } + ], + "htmlcontent": + [ + { "url": "@host/test.php", "content": "

Server up!

" } + ], + "ping": + [ + {} + ] + } + } + }, + "hostgroups": + { + "all": + { + "members": ["admin"], + "hosts": ["hanez"], + "parent": "network", + "threshold": 10, + "services": + { + "ping": ["do_every_x_times"] + } + } + }, + "layouts": {"production": {"hostgroups": ["all", "hanez", "network"], "enabled": true}, + "lazy": {"hostgroups": ["hanez", "ruff"], "enabled": false} + }, + "core": { + "max_logfile_size": 1024000, + "max_logfile_count": 4, + "max_worker_threads": 8 + } +}