addes ome broken code to mariadb task; just playing around...

This commit is contained in:
Johannes Findeisen 2013-11-22 21:10:08 +01:00
commit 86107d60b3

View file

@ -1,6 +1,8 @@
""" """
The MariaDB task The MariaDB task
Uses: http://sourceforge.net/projects/mysql-python
Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg
This file is part of Linspector (http://linspector.org). 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 <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
import MySQLdb
from logging import getLogger from logging import getLogger
from linspector.tasks.task import Task from linspector.tasks.task import Task
@ -28,7 +32,51 @@ logger = getLogger(__name__)
class MariadbTask(Task): class MariadbTask(Task):
def __init__(self, **kwargs): 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): def create(kwargs):