From bd7955c8ca6239aa33c4d87478687cd87664f221 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 11 Nov 2013 07:05:19 +0100 Subject: [PATCH] many small fixes... :) --- linspector/services/etc/shell.py | 2 +- linspector/services/http/http.py | 93 --------------------------- linspector/services/net/ping.py | 2 +- linspector/services/net/udpconnect.py | 72 --------------------- linspector/services/snmp/snmpget.py | 2 +- linspector/services/ssh/ssh.py | 9 +-- 6 files changed, 4 insertions(+), 176 deletions(-) delete mode 100644 linspector/services/http/http.py delete mode 100644 linspector/services/net/udpconnect.py diff --git a/linspector/services/etc/shell.py b/linspector/services/etc/shell.py index 61d77fd..9b1bfda 100644 --- a/linspector/services/etc/shell.py +++ b/linspector/services/etc/shell.py @@ -1,7 +1,7 @@ """ The shell service. This is for executing local shell commands and retrieve the output. -Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg" +Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). diff --git a/linspector/services/http/http.py b/linspector/services/http/http.py deleted file mode 100644 index 9765755..0000000 --- a/linspector/services/http/http.py +++ /dev/null @@ -1,93 +0,0 @@ -""" -The http service. - -This is for checking the availability and output of HTTP services. Basic HTTP -content could be fetched and compared.HTTPS is not validating the server -certificate! - -Uses: https://github.com/kennethreitz/requests in the near future! - -This should just return 0 on success and NOT 0 on error. Just to make internals -generic to just report this code and not use a parser. - -Copyright (c) 2011-2013 by 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 . -""" - -import urllib - -from logging import getLogger - -from linspector.services.service import Service - -logger = getLogger(__name__) - - -class HttpService(Service): - def __init__(self, **kwargs): - super(HttpService, self).__init__(**kwargs) - - args = self.get_arguments() - if "content" in args: - self.content = args["content"] - else: - raise Exception("There is no content set") - - self.method = "get" - if "method" in args: - self.method = args["method"] - - self.params = None - if "params" in args: - self.params = kwargs["params"] - - self.path = "/" - if "path" in args: - self.path = kwargs["path"] - - self.port = "80" - if "port" in args: - self.port = kwargs["port"] - - self.protocol = "http" - if "protocol" in args: - self.protocol = kwargs["protocol"] - - def needs_arguments(self): - return True - - def execute(self, jobInfo): - params = urllib.urlencode(self.params) - - if self.method is "get": - f = urllib.urlopen(self.protocol + "://" + self._host + ":" + self.port + self.path + "?%s" % params) - elif self.method is "post": - f = urllib.urlopen(self.protocol + "://" + self._host + ":" + self.port + self.path, params) - - if self.content not in f.read(): - jobInfo.set_errorcode(1) - jobInfo.set_message("[http: " + jobInfo.jobHex + "] Content not found on host: " + - jobInfo.get_host() + " on port: " + str(self.port)) - elif jobInfo.get_errorcode() == -1: - jobInfo.set_execution_successful(True) - jobInfo.set_errorcode(0) - jobInfo.set_message("[http: " + jobInfo.jobHex + "] Content found on host: " + - jobInfo.get_host() + " on port: " + str(self.port)) - - -def create(kwargs): - return HttpService(**kwargs) \ No newline at end of file diff --git a/linspector/services/net/ping.py b/linspector/services/net/ping.py index d647f20..0869aab 100644 --- a/linspector/services/net/ping.py +++ b/linspector/services/net/ping.py @@ -1,7 +1,7 @@ """ The ping service in pure Python. -Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg" +Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). diff --git a/linspector/services/net/udpconnect.py b/linspector/services/net/udpconnect.py deleted file mode 100644 index 5d6ad55..0000000 --- a/linspector/services/net/udpconnect.py +++ /dev/null @@ -1,72 +0,0 @@ -""" -The udpconnect service. This is to check if a UDP service on a specific -port is reachable. - -This should just return 0 on success and NOT 0 on error. - -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 . -""" - -import socket - -from logging import getLogger - -from linspector.services.service import Service - -logger = getLogger(__name__) - - -class UdpconnectService(Service): - def __init__(self, **kwargs): - super(UdpconnectService, self).__init__(**kwargs) - - args = self.get_arguments() - if "port" in args: - self.port = args["port"] - else: - raise Exception("There is no port set") - - def needs_arguments(self): - return True - - def execute(self, jobInfo): - try: - sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - except socket.error, msg: - jobInfo.set_errorcode(2) - jobInfo.set_message("[udpconnect: " + jobInfo.jobHex + "] Could not create socket to host: " + - jobInfo.get_host() + " on port: " + str(self.port) + " (" + str(msg) + ")") - - try: - sock.connect((jobInfo.get_host(), self.port)) - except socket.error, msg: - jobInfo.set_errorcode(1) - jobInfo.set_message("[udpconnect: " + jobInfo.jobHex + "] Could not establish connection to host: " + - jobInfo.get_host() + " on port: " + str(self.port) + " (" + str(msg) + ")") - - if jobInfo.get_errorcode() == -1: - jobInfo.set_execution_successful(True) - jobInfo.set_errorcode(0) - jobInfo.set_message("[udpconnect: " + jobInfo.jobHex + "] Connection successful established to host: " + - jobInfo.get_host() + " on port: " + str(self.port)) - - sock.close() - - -def create(kwargs): - return UdpconnectService(**kwargs) \ No newline at end of file diff --git a/linspector/services/snmp/snmpget.py b/linspector/services/snmp/snmpget.py index dbb6961..271c0fe 100644 --- a/linspector/services/snmp/snmpget.py +++ b/linspector/services/snmp/snmpget.py @@ -1,7 +1,7 @@ """ The snmpget service in pure Python. -Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg" +Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). diff --git a/linspector/services/ssh/ssh.py b/linspector/services/ssh/ssh.py index 2589579..0236702 100644 --- a/linspector/services/ssh/ssh.py +++ b/linspector/services/ssh/ssh.py @@ -3,7 +3,7 @@ The ssh service This is for executing remote shell commands and retrieve the out This service is using paramiko (http://www.lag.net/paramiko/). -Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg" +Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). @@ -65,10 +65,3 @@ class SshService(Service): def create(kwargs): return SshService(**kwargs) - -# def main(): -# # service = SshService(parser, log, command='uptime') -# return -# -# if __name__ == "__main__": -# main() \ No newline at end of file