Skip to content

Instantly share code, notes, and snippets.

@LKLG
Last active September 2, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LKLG/6c441f88094e2269757f to your computer and use it in GitHub Desktop.
Save LKLG/6c441f88094e2269757f to your computer and use it in GitHub Desktop.
Show ticket-statistic from OTRS

Dashing OTRS-Tickets Widget

About

This widget gives you a overview of your today's opened and closed tickets. You can use this perfectly with my miniwidget.

Installation

  1. From your Dashing Dashboard's directory, use the command: dashing install 6c441f88094e2269757f
  2. Edit otrs.rb and put your MySQL-Connectiondata on line 41

License

Datenlizenz Deutschland – Namensnennung – Version 1.0

Jede Nutzung mit Quellenvermerk ist zulässig.

Veränderungen, Bearbeitungen, neue Gestaltungen oder sonstige Abwandlungen sind mit einem Veränderungshinweis im Quellenvermerk zu versehen oder der Quellenvermerk ist zu löschen, sofern die datenhaltende Stelle dies verlangt.

Der Bereitsteller stellt die Daten, Inhalte und Dienste mit der zur Erfüllung seiner öffentlichen Aufgaben erforderlichen Sorgfalt zur Verfügung. Für die Daten, Inhalte und Dienste gelten in Bezug auf deren Verfügbarkeit und deren Qualität die durch den Bereitsteller in den Metadaten oder sonstigen Beschreibungen zugewiesenen Spezifikationen und Qualitätsmerkmale. Der Bereitsteller übernimmt jedoch keine Gewähr für die Richtigkeit und Vollständigkeit der Daten und Inhalte sowie die dauerhafte Verfügbarkeit der Dienste. Davon ausgenommen sind Schadensersatzansprüche aufgrund einer Verletzung des Lebens, körperliche Unversehrtheit oder Gesundheit. Ebenfalls ausgenommen sind Schäden, die auf Vorsatz oder grober Fahrlässigkeit beruhen.

Data licence Germany – attribution – Version 1.0

Any use shall be permitted provided the source is mentioned.

Changes, editing, new designs or other amendments shall be marked with information in the source note about relevant changes, or the source note must be deleted if the entity keeping the data requires so.

The provider makes available the data, contents and services with the diligence necessary for the discharge of its public tasks. With reference to their availability and quality, the specifications and quality features assigned by the provider in the meta-data or other descriptions apply to the data, contents and services. However, the provider does not assume any liability for the accuracy and completeness of data and contents and for permanent availability of services. Exempt from this are any claims for damage due to an injury to life, limb or health. Also exempt is damage based on wilfulness or gross negligence.

def request(query,table,server,user,pw,conv=true,multi=false)
require 'dbi'
begin
dbh = DBI.connect("DBI:Mysql:#{table}:#{server}","#{user}","#{pw}")
sth = dbh.prepare(query)
sth.execute
if multi == true then
i = 0
erg = []
sth.fetch do |row|
erg[i] = row[0]
i += 1
end
else
erg = sth.fetch
end
end
if conv == true then
if erg.class.to_s == "Array" then
erg = erg[0]
end
end
return erg
end
def prevdays(days)
require 'time'
date = Array.new
sec = 86400
seconds = sec * days
time = Time.new.to_time.to_i
date[0] = time - seconds
prev = Time.at(date[0]).to_s
date[1] = prev.gsub!(/[0-9][0-9][:][0-9][0-9][:][0-9][0-9] .*/,"00:00:00")
date[2] = date[1].sub("00:00:00","23:59:59")
date
end
def get()
conndata = ["TABLE","SERVER","USER","PWD"]
between = prevdays(0)
query_closed = "SELECT COUNT(*) AS Anzahl FROM ticket WHERE ticket_state_id='2' AND change_time BETWEEN '#{between[1]}' AND '#{between[2]}'"
query_new = "SELECT COUNT(*) AS Anzahl FROM ticket WHERE change_time BETWEEN '#{between[1]}' AND '#{between[2]}' AND create_time BETWEEN '#{between[1]}' AND '#{between[2]}'"
ergc = request(query_closed,conndata[0],conndata[1],conndata[2],conndata[3])
ergn = request(query_new,conndata[0],conndata[1],conndata[2],conndata[3])
return [ergc,ergn]
end
SCHEDULER.every '1m' do |job|
tickets = get(0)
tickets = "#{tickets[0][0].to_i}:#{tickets[1][0].to_i}"
send_event('tickets',text:tickets)
end
@Aairborn
Copy link

Aairborn commented Sep 2, 2015

Hello,
I really would like to use this script to show some otrs statistics on our dashing board but sadly it´s not working. Could somebody explain this a littlebit more?

What I have so far:

  • a working Dashing Dashboard Server
  • a working OTRS Server
  • I´m able to connect via MySQL console from Dashing Server to OTRS Server
  • dashing install 6c441f88094e2269757f (done)
  • Edit otrs.rb and put your MySQL-Connectiondata on line 41 (done)
  • added to the gem file gem 'dbi' and run bundle install (ok)
  • added to the gem file gem 'time' and run bundle install ... but it always says .... Resolving dependencies...
    Could not find gem 'time (>= 0) ruby' in the gems available on this machine.
  • gem list -r ... there is no gem 'time'
  • ruby -v = ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

And into the dashboard.erb file i´ve made the following entry:
data-row="2" data-col="1" data-sizex="1" data-sizey="2"
data-id="tickets" data-view="Text" data-title="OTRS Tickets"
(the li and div Tags are there but wouldnt be shown in the comments)

every little help would be highly welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment