diff --git a/linspector/tasks/storage/mariadb.py b/linspector/tasks/storage/mariadb.py index 8965648..8f1b101 100644 --- a/linspector/tasks/storage/mariadb.py +++ b/linspector/tasks/storage/mariadb.py @@ -1,6 +1,8 @@ """ The MariaDB task +Uses: http://sourceforge.net/projects/mysql-python + Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg This file is part of Linspector (http://linspector.org). @@ -19,6 +21,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ +import MySQLdb + from logging import getLogger from linspector.tasks.task import Task @@ -28,7 +32,51 @@ logger = getLogger(__name__) class MariadbTask(Task): def __init__(self, **kwargs): - pass + super(MariadbTask, self).__init__(**kwargs) + + args = self.get_arguments() + + if "database" in args: + self.database = args["database"] + else: + raise Exception("There is no database set") + + self.table = "default" + if "table" in args: + self.table = args["table"] + + self.host = "localhost" + if "host" in args: + self.host = args["host"] + + self.port = 3600 + if "port" in args: + self.port = args["port"] + + self.username = None + if "username" in args: + self.username = args["username"] + + self.password = None + if "password" in args: + self.password = args["password"] + + self.db = MySQLdb.connect(host=self.host, + port=self.port, + user=self.username, + passwd=self.password, + db=self.database) + self.cur = self.db.cursor() + + def needs_arguments(self): + return True + + def execute(self, job_information): + data = str(job_information.get_job_id()) + "," + \ + str(job_information.get_response_message()) + "," + \ + str(job_information.get_status()) + + self.cur.execute("INSERT INTO " + self.table + " (job_id,msg,status) VALUES (" + data + ")") def create(kwargs):