# HG changeset patch # User sean # Date 1438691033 -7200 # Node ID 7a573ec679a69524e59365fe1500043dff4ea5c3 # Parent d71f39618d6ff4a003c53e310a2131613a4d6390 added more files, can now display charts a bit diff -r d71f39618d6f -r 7a573ec679a6 dash.conf --- a/dash.conf Wed Jul 29 12:27:26 2015 +0200 +++ b/dash.conf Tue Aug 04 14:23:53 2015 +0200 @@ -61,16 +61,5 @@ status=up [tile4] -type=mon -source=192.168.4.3 -status=up - -[tile5] -type=mon -source=192.168.4.3 -status=up - -[tile6] -type=mon -source=192.168.4.3 -status=up +type=d3js +status=modules/roundup-cc/display_issues._techintern.py diff -r d71f39618d6f -r 7a573ec679a6 doc/connect_with_mon/bottledash.alert --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/connect_with_mon/bottledash.alert Tue Aug 04 14:23:53 2015 +0200 @@ -0,0 +1,54 @@ +#!/usr/bin/perl +# +# +# Sean Engelhardt, sean.engelhardt@intevation.de +# +# +# Copyright (C) 2015, Intevation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +#STD +use Getopt::Std; + +#get LWP functionallity +use LWP::UserAgent; + +#alert-status propbably? every Mon-alert uses that +getopts ("s:g:h:t:l:u"); + +#Creates a new LWP-use-agent +my $ua = LWP::UserAgent->new; + +#defines the server-Endpoint. Usually the bottledash-server +my $server_endpoint = "http://:8080/updown"; + +#determinates if the altert is an upalert or a "down"-alert +$ALERT = $opt_u ? "UPALERT" : "ALERT"; + +# set custom HTTP request header fields +my $req = HTTP::Request->new(POST => $server_endpoint); +$req->header('content-type' => 'application/json'); +$req->header('x-auth-token' => 'kfksj48sdfj4jd9d'); + +# add POST data to HTTP request body +my $post_data = '{ "server": $ALERT, "status": $opt_u }'; +$req->content($post_data); + +#every-alert uses that. Dont know what that is +while () { + print; +} \ No newline at end of file diff -r d71f39618d6f -r 7a573ec679a6 modules/roundup_cc/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/roundup_cc/__init__.py Tue Aug 04 14:23:53 2015 +0200 @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +""" supplys the data needed to comunicate with the roundup-server, +and the sqlite database. Represents the types of errors used in roundup. + +author: Sascha L. Teichmann +author: Bernhard Reiter +author: Sean Engelhardt + +(c) 2010,2015 by Intevation GmbH + +This is Free Software unter the terms of the +GNU GENERAL PUBLIC LICENSE Version 3 or later. +See http://www.gnu.org/licenses/gpl-3.0.txt for details +""" + +import roundup_cc.display_issues as display +import roundup_cc.roundup_content_data as rcd + +def get_tech_intern_chart(): + return display.render_db_stats_as_html(rcd.DATABASE_TECH_INTERN, rcd.SELECT_ALL) diff -r d71f39618d6f -r 7a573ec679a6 modules/roundup_cc/collect_issues.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/roundup_cc/collect_issues.py Tue Aug 04 14:23:53 2015 +0200 @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 + +""" Fetch issues from a roundup-tracker and save them in a databse. + +author: Sascha L. Teichmann +author: Bernhard Reiter +author: Sean Engelhardt + +(c) 2010,2015 by Intevation GmbH + +This is Free Software unter the terms of the +GNU GENERAL PUBLIC LICENSE Version 3 or later. +See http://www.gnu.org/licenses/gpl-3.0.txt for details + + +##USAGE EXAMPLE: ## + +BASE_URL_DEMO = "http://localhost:8917/demo/" +SEARCH_URL_DEMO = "issue?@action=export_csv&@columns=title,priority&@filter=status&@pagesize=50&@startwith=0&status=-1,1,2,3,4,5,6,7" + +LOGIN_PARAMETERS_DEMO = ( + ("__login_name", "demo"), + ("__login_password", "demo"), + ("@action", "Login"), + ) + +save_stats_in_db(LOGIN_PARAMETERS_DEMO, BASE_URL_DEMO, rcd.DATABASE_DEMO, rcd.COLUMNS, rcd.CREATE_DB, rcd.INSERT_NEW, SEARCH_URL_DEMO) +""" + +import http.cookiejar +import urllib.parse +import urllib.request +import csv +import io +import sqlite3 as db +import os +import roundup_cc.roundup_content_data as rcd + + +CHECK_ROUNDUP_ORDER = "priority?@action=export_csv&@columns=id,order" +CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id&@filter=open&open=1" +SEARCH_ROUNDUP = "issue?@action=export_csv&@columns=priority&@filter=status&@pagesize=500&@startwith=0&status=-1,{search_values}" + + +def connect_to_server(params, baseurl): + enc_data = urllib.parse.urlencode(params).encode() + cj = http.cookiejar.CookieJar() + opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) + req = urllib.request.Request(url=baseurl, data=enc_data) + opener.open(req) + return opener + + +def get_csv_from_server(opener, roundup_url, sub_url): + csv_req = urllib.request.Request(url=roundup_url+sub_url) + f = opener.open(csv_req) + csv_reader = csv.DictReader(io.TextIOWrapper(f)) + return csv_reader + + +def set_search_paramters_on_URL(url, search_param_csv): + + id_list = [] + + for row in search_param_csv: + id_list.append(row["id"]) + + new_url = url.format(search_values = ",".join(id_list)) + + return new_url + + +def check_create_database(database_file, sql_create_db): + if not os.path.isfile(database_file): + con = None + cur = None + try: + con = db.connect(database_file) + cur = con.cursor() + try: + cur.execute(sql_create_db) + con.commit() + os.chmod(database_file, 0o644) + except: + con.rollback() + raise + finally: + if cur: + cur.close() + if con: + con.close() + + +def issues_to_quantities(issue_csv, columns, orders_csv): + + quantities = [0] * len(columns) + order_dict = {} + + #convert the csv-dict reader to real dict + for row in orders_csv: + order_dict[row["id"]] = int(float(row["order"])) # int(float()) because the order-value is indeed "1.0, 2.0" etc + + for issue in issue_csv: + priority = issue["priority"] + + if priority.isdigit() == True : + quantities[order_dict[priority] -1 ] += 1 + + # print("quantities : " + str(quantities)) + + return quantities + + +def save_issues_to_db(quantities, database_file, sql_create_db, sql_insert_in_db): + check_create_database(database_file, sql_create_db) + + cur = None + con = None + + try: + con = db.connect(database_file) + cur = con.cursor() + try: + cur.execute(sql_insert_in_db, quantities) + con.commit() + except: + con.rollback() + raise + finally: + if cur: + cur.close() + if con: + con.close() + + +def save_stats_in_db(login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, searchurl=False): + try: + + opener = connect_to_server(login_parmeters, baseurl) + + search_operators_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES) + order_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_ORDER) + + if searchurl == False: + formated_search_url = set_search_paramters_on_URL(SEARCH_ROUNDUP, search_operators_csv) + else: + formated_search_url = searchurl + + current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url) + + opener.close() + + quantities = issues_to_quantities(current_issues_csv, columns, order_csv) + + save_issues_to_db(quantities, db_file, sql_create_db, sql_insert_in_db) + + except urllib.error.URLError as e: + print("No Valid Connection to server : " + baseurl + "\nerror: " + str(e)) diff -r d71f39618d6f -r 7a573ec679a6 modules/roundup_cc/display_issues.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/roundup_cc/display_issues.py Tue Aug 04 14:23:53 2015 +0200 @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 + +""" Display previously saved issues from a database on webpage via CGI. + +author: Sascha L. Teichmann +author: Bernhard Reiter +author: Sean Engelhardt + +(c) 2010,2015 by Intevation GmbH + +This is Free Software unter the terms of the +GNU GENERAL PUBLIC LICENSE Version 3 or later. +See http://www.gnu.org/licenses/gpl-3.0.txt for details + + +##Usage Example: ## + +render_db_stats_as_html(rcd.DATABASE_DEMO, rcd.SELECT_ALL) +""" + +import sqlite3 as db +import cgitb, os, sys +import roundup_cc.roundup_content_data as rcd + +PATH = os.path.abspath(os.path.dirname(sys.argv[0])) +HTML_DATA = "graph.html" +PATH_TO_HTML = PATH + "/modules/roundup_cc/" + HTML_DATA + +def make_js_object_string(array): + formated = [] + + for item in array: + formated.append("{points: " + str(item) + "}") + + return ",".join(formated) + + +def make_js_object_date(array): + formated = [] + + for item in array: + formated.append("{date : new Date('" + str(item) + "')}") + + return ", ".join(formated) + + +def get_webpage(): + + with open(PATH_TO_HTML, "r") as html_chart_file: + base_html_data = html_chart_file.read() + + base_html_data = (base_html_data + .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") + .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") + .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") + .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") + .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") + .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) + + return base_html_data + + +# def render_webpage(content): +# webpage_string = "" +# for line in content.split("\n"): +# print(line) + + +def render_db_stats_as_html(db_file, sql_select): + + con = None + cur = None + + try: + con = db.connect(db_file) + cur = con.cursor() + cur.execute(sql_select) + + for row in cur.fetchall(): + rcd.data_dict["date"].append(row[0]) + rcd.data_dict["critical"].append(row[1]) + rcd.data_dict["urgent"].append(row[2]) + rcd.data_dict["bug"].append(row[3]) + rcd.data_dict["feature"].append(row[4]) + rcd.data_dict["wish"].append(row[5]) + finally: + if cur: + cur.close() + if con: + con.close() + + # render_webpage(get_webpage()) + # print(get_webpage()) + return get_webpage() + +# cgitb.enable() +# print("Content-Type: text/html") +# print() diff -r d71f39618d6f -r 7a573ec679a6 modules/roundup_cc/graph.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/roundup_cc/graph.html Tue Aug 04 14:23:53 2015 +0200 @@ -0,0 +1,408 @@ + + + + + diff -r d71f39618d6f -r 7a573ec679a6 modules/roundup_cc/roundup_content_data/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/roundup_cc/roundup_content_data/__init__.py Tue Aug 04 14:23:53 2015 +0200 @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +""" supplys the data needed to comunicate with the roundup-server, +and the sqlite database. Represents the types of errors used in roundup. + +author: Sascha L. Teichmann +author: Bernhard Reiter +author: Sean Engelhardt + +(c) 2010,2015 by Intevation GmbH + +This is Free Software unter the terms of the +GNU GENERAL PUBLIC LICENSE Version 3 or later. +See http://www.gnu.org/licenses/gpl-3.0.txt for details +""" + +import os + +#Add desired sqlite databases here +DATABASE_REFERENCCE = os.path.dirname(os.path.realpath(__file__)) + "/test_reference.db" +DATABASE_DEMO = os.path.dirname(os.path.realpath(__file__)) + "/demo.db" +DATABASE_ERRORDB = os.path.dirname(os.path.realpath(__file__)) + "/errordatabase.db" +DATABASE_TECH_INTERN = os.path.dirname(os.path.realpath(__file__)) + "/tech_intern.db" +DATABASE_INT_TEST = os.path.dirname(os.path.realpath(__file__)) + "/int_test.db" + +COLUMNS= [ + "critical", "urgent", "bug", "feature", "wish", +] + +data_dict = { + "date": [], + "critical": [], + "urgent": [], + "bug": [], + "feature": [], + "wish": [] +} + +#SQL + +#DEMO System +SELECT_ALL = """ +SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp), + critical, + urgent, + bug, + feature, + wish +FROM issues +ORDER BY timestamp +""" + + +CREATE_DB = """ +CREATE TABLE issues ( + timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp, + critical INTEGER NOT NULL DEFAULT 0, + urgent INTEGER NOT NULL DEFAULT 0, + bug INTEGER NOT NULL DEFAULT 0, + feature INTEGER NOT NULL DEFAULT 0, + wish INTEGER NOT NULL DEFAULT 0 +) +""" + + +INSERT_NEW = """ + INSERT INTO issues (critical, urgent, bug, feature, wish) + VALUES (?, ?, ?, ?, ?) +""" + +#Referecen DB: +SELECT_ALL_REFERENCE = """ +SELECT strftime("%Y-%m-%dT%H:%M:%S", sample_time), + critical, + major, + crash, + normal, + minor, + wishlist +FROM issues +ORDER BY sample_time +""" \ No newline at end of file diff -r d71f39618d6f -r 7a573ec679a6 views/hello_template.tpl --- a/views/hello_template.tpl Wed Jul 29 12:27:26 2015 +0200 +++ b/views/hello_template.tpl Tue Aug 04 14:23:53 2015 +0200 @@ -3,23 +3,25 @@ License: GNU GPL >= v2. See LICENSE for details. --> <% + import math, os, sys, subprocess, html.parser - import math from datetime import date + h = html.parser.HTMLParser() + PATH = os.path.abspath(os.path.dirname(sys.argv[0])) + sys.path.append(PATH + "/modules") + import roundup_cc + ################# # settings # ################# - show_top_bar = settings["show_top_bar"] - ################# # date and time # ################# - today = date.today() weekday = ("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag")[today.weekday()] @@ -177,7 +179,6 @@ % end
- <% for tile in tiles : type = "" @@ -191,13 +192,16 @@ elif tile["status"] == "down" : status = "dead" end - elif tile["type"] == "d3.js" : + elif tile["type"] == "d3js" : type = "chart" - text = "place for a chart!" + status = "" + text = roundup_cc.get_tech_intern_chart() + #text = "
HHOHOHOHOH
" end %> +
- {{text}} + {{!text}}
% end