moved linspector to bin and renamed lib
This commit is contained in:
parent
fc4a55c8db
commit
4f6639b259
47 changed files with 24 additions and 161 deletions
137
linspector
137
linspector
|
|
@ -1,137 +0,0 @@
|
|||
#!/usr/bin/python2.7 -tt
|
||||
|
||||
"""
|
||||
Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg"
|
||||
|
||||
This file is part of Linspector (http://linspector.org).
|
||||
|
||||
Linspector is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
__version__ = "0.6/TCPCONNECT"
|
||||
__default_config__ = "./examples/minimal.json"
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os
|
||||
import os.path as path
|
||||
|
||||
from lib.config.parser import FullConfigParser
|
||||
from lib.core.job import Job
|
||||
from lib.core.scheduler import Scheduler
|
||||
from lib.backends.https import HttpsBackend
|
||||
from lib.frontends.lish import LishFrontend
|
||||
|
||||
|
||||
def parseArgs():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Linspector is for monitoring the vital information of hosts, services and devices in a network.",
|
||||
epilog="linspector is not some program expecting computers to run! Visit http://linspector.org for more "
|
||||
"information.",
|
||||
prog="linspector")
|
||||
|
||||
parser.add_argument("--version", action="version", version="%(prog)s " + str(__version__))
|
||||
#TODO: make the config file a required field without -c or --config at the end eg: linspector config.json
|
||||
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")
|
||||
|
||||
output = parser.add_mutually_exclusive_group()
|
||||
output.add_argument("-q", "--quiet", action="store_const", dest="loglevel", const=logging.ERROR,
|
||||
help="output only errors")
|
||||
output.add_argument("-w", "--warning", action="store_const", dest="loglevel", const=logging.WARNING,
|
||||
help="output warnings")
|
||||
output.add_argument("-v", "--verbose", action="store_const", dest="loglevel", const=logging.INFO,
|
||||
help="output info messages")
|
||||
output.add_argument("-d", "--debug", action="store_const", dest="loglevel", const=logging.DEBUG,
|
||||
help="output debug messages")
|
||||
output.set_defaults(loglevel=logging.INFO)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def setupLogging(logfile="./log/linspector.log", logLevel=logging.DEBUG, logfileLevel=logging.DEBUG):
|
||||
logfile = path.expanduser(logfile)
|
||||
if not path.exists(path.dirname(logfile)):
|
||||
os.makedirs(path.dirname(logfile))
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
consoleHandler = logging.StreamHandler()
|
||||
consoleHandler.setLevel(logLevel)
|
||||
|
||||
fileHandler = logging.handlers.RotatingFileHandler(logfile, maxBytes=1024000, backupCount=4)
|
||||
fileHandler.setLevel(logfileLevel)
|
||||
|
||||
consoleFormatter = logging.Formatter('[%(levelname)s]: %(message)s')
|
||||
#TODO: if debug with file and function else without that
|
||||
fileFormatter = logging.Formatter('%(asctime)s %(pathname)s %(module)s %(funcName)s %(lineno)d [%(levelname)s]: %(message)s')
|
||||
|
||||
consoleHandler.setFormatter(consoleFormatter)
|
||||
fileHandler.setFormatter(fileFormatter)
|
||||
|
||||
log.addHandler(consoleHandler)
|
||||
log.addHandler(fileHandler)
|
||||
return log
|
||||
|
||||
|
||||
def handleJob(jobInfo):
|
||||
jobInfo.handle_call()
|
||||
|
||||
|
||||
def main():
|
||||
args = parseArgs()
|
||||
#TODO: catch all log messages (apscheduler etc.); make logging more generic to support libraries logging
|
||||
log = setupLogging(args.logfile, args.loglevel)
|
||||
|
||||
log.info("parsed arguments")
|
||||
|
||||
configParser = FullConfigParser(log)
|
||||
linConf, core = configParser.parse_config(args.config)
|
||||
|
||||
scheduler = Scheduler()
|
||||
|
||||
scheduler.start()
|
||||
jobs = []
|
||||
|
||||
for layout in linConf.get_enabled_layouts():
|
||||
for hostgroup in layout.get_hostgroups():
|
||||
for service in hostgroup.get_services():
|
||||
for host in hostgroup.get_hosts():
|
||||
for period in service.get_periods():
|
||||
job = Job(service, host, hostgroup.get_members(), hostgroup.get_processors(), core)
|
||||
schedulerJob = period.createJob(scheduler, job, handleJob)
|
||||
if schedulerJob is not None:
|
||||
job.set_job(schedulerJob)
|
||||
job.set_logger(log)
|
||||
jobs.append(job)
|
||||
|
||||
#TODO: Load Backend Threads here before initializing the frontend.
|
||||
'''
|
||||
for backend in backends.enabled
|
||||
backend.start
|
||||
|
||||
take care of signals etc. to sthutdown the threads when stopping linspector.
|
||||
'''
|
||||
frontend = LishFrontend(jobs=jobs, scheduler=scheduler, linspectorConfig=linConf)
|
||||
|
||||
log.debug("shutting down scheduler")
|
||||
logging.shutdown()
|
||||
scheduler.shutdown(wait=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -22,7 +22,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.backends.backend import Backend
|
||||
from linspector.backends.backend import Backend
|
||||
|
||||
|
||||
class HttpsBackend(Backend):
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.backends.backend import Backend
|
||||
from linspector.backends.backend import Backend
|
||||
|
||||
|
||||
class JsonrpcBackend(Backend):
|
||||
|
|
@ -22,7 +22,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.backends.backend import Backend
|
||||
from linspector.backends.backend import Backend
|
||||
|
||||
|
||||
class XmmpBackend(Backend):
|
||||
|
|
@ -28,10 +28,10 @@ from members import Member
|
|||
from config import LinspectorConfig
|
||||
from periods import CronPeriod, DatePeriod, IntervalPeriod
|
||||
|
||||
from lib.services.service import Service
|
||||
from lib.processors.processor import Processor
|
||||
from lib.parsers.parser import Parser
|
||||
from lib.tasks.task import Task
|
||||
from linspector.services.service import Service
|
||||
from linspector.processors.processor import Processor
|
||||
from linspector.parsers.parser import Parser
|
||||
from linspector.tasks.task import Task
|
||||
|
||||
MOD_SERVICES = "services"
|
||||
MOD_PROCESSORS = "processors"
|
||||
|
|
@ -127,7 +127,7 @@ class ConfigParser:
|
|||
return mods[clazz]
|
||||
else:
|
||||
#mod = __import__(clazz)
|
||||
p = join("lib", modPart, clazz + ".py")
|
||||
p = join("linspector", modPart, clazz + ".py")
|
||||
mod = imp.load_source(clazz, p)
|
||||
mods[clazz] = mod
|
||||
return mod
|
||||
|
|
@ -22,7 +22,7 @@ from ..core.daemon import Daemon
|
|||
|
||||
"""
|
||||
TODO: Think about, that daemonizing this software is not our goal but when we want to that, this needs a rewrite and
|
||||
should maybe move over to the daemon frontend. daemon.py will remain the the base for this and should stay in lib/core .
|
||||
should maybe move over to the daemon frontend. daemon.py will remain the the base for this and should stay in linspector/core .
|
||||
Since a daemon it normally not a frontend we should think about how to handle this. When daemonizing a real frontend
|
||||
like "Lish" will make no sense but a frontend like "https" or "xmpp" could be useful anyway...
|
||||
"""
|
||||
|
|
@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
|
||||
from lib.frontends.frontend import Frontend
|
||||
from linspector.frontends.frontend import Frontend
|
||||
import os
|
||||
from shlex import split as shsplit
|
||||
from cmd import Cmd
|
||||
|
|
@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.parsers.parser import Parser
|
||||
from linspector.parsers.parser import Parser
|
||||
|
||||
|
||||
class ShellParser(Parser):
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.processors.processor import Processor
|
||||
from linspector.processors.processor import Processor
|
||||
|
||||
|
||||
class MariadbProcessor(Processor):
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.processors.processor import Processor
|
||||
from linspector.processors.processor import Processor
|
||||
|
||||
|
||||
class MongodbProcessor(Processor):
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.processors.processor import Processor
|
||||
from linspector.processors.processor import Processor
|
||||
|
||||
|
||||
class SyslogProcessor(Processor):
|
||||
|
|
@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import urllib
|
||||
from lib.services.service import Service
|
||||
from linspector.services.service import Service
|
||||
|
||||
|
||||
class HttpService(Service):
|
||||
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
# http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/
|
||||
from lib.services.service import Service
|
||||
from linspector.services.service import Service
|
||||
import struct
|
||||
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.services.service import Service
|
||||
from linspector.services.service import Service
|
||||
|
||||
|
||||
class ShellService(Service):
|
||||
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
#from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||
from lib.services.service import Service
|
||||
from linspector.services.service import Service
|
||||
|
||||
|
||||
class SnmpgetService(Service):
|
||||
|
|
@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import paramiko
|
||||
import pprint
|
||||
import os
|
||||
from lib.services.service import Service
|
||||
from linspector.services.service import Service
|
||||
|
||||
|
||||
class SshService(Service):
|
||||
|
|
@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import socket
|
||||
from lib.services.service import Service
|
||||
from linspector.services.service import Service
|
||||
|
||||
|
||||
class TcpconnectService(Service):
|
||||
0
linspector/tasks/__init__.py
Normal file
0
linspector/tasks/__init__.py
Normal file
|
|
@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import xmpp
|
||||
from lib.tasks.task import Task
|
||||
from linspector.tasks.task import Task
|
||||
|
||||
|
||||
class JabberTask(Task):
|
||||
|
|
@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import datetime
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from lib.tasks.task import Task
|
||||
from linspector.tasks.task import Task
|
||||
|
||||
|
||||
class MailTask(Task):
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from lib.tasks.task import Task
|
||||
from linspector.tasks.task import Task
|
||||
|
||||
|
||||
class SmsTask(Task):
|
||||
|
|
@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import tweepy
|
||||
from lib.tasks.task import Task
|
||||
from linspector.tasks.task import Task
|
||||
|
||||
|
||||
class TweetTask(Task):
|
||||
Loading…
Add table
Add a link
Reference in a new issue