Skip to content

Instantly share code, notes, and snippets.

@joren
Last active December 21, 2015 14:18
Show Gist options
  • Save joren/6318472 to your computer and use it in GitHub Desktop.
Save joren/6318472 to your computer and use it in GitHub Desktop.

Description

Simple Dashing widget that show the amount of open tickets for a SirPortly departement.

The widget was made by @joren for use @openminds. If you end up using this widget, please send me a tweet! I'd love to hear about it.

Dependencies

This widget requires the sirportly gem for API communication.

Usage

This widgets uses the number-widget, so no need to create a new one. You can add as much departements as you want in the config file. Add the team, domain, api credentials, statuses, warning- and danger-tresholds to the config file at config/sirportly.yml for each department you cant to add.

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="sirportly_departmentname" data-view="Number" data-title="Support tickets" value="0"></div>
</li>

And that is all.

Contributing

Have tips on making this better? Please leave a comment and/or fork the gist. Sending me a tweet on Twitter is probably a good idea as well!

require 'sirportly'
begin
sirportly_config = YAML.load_file("config/sirportly.yml")
departments = sirportly_config['departments']
departments.each do |name, department|
SCHEDULER.every '1m', :first_in => 0 do |job|
Sirportly.domain = department['domain']
sirportly = Sirportly::Client.new(department['api_token'], department['api_secret'])
ticket_count = sirportly.spql("SELECT COUNT FROM tickets WHERE teams.name = '#{department['team']}' AND ((status.name = #{department['statuses'].join(' OR status.name = ')}))").results.flatten.first
status = "ok"
status = "warning" if ticket_count.to_i > department['warning_threshold']
status = "danger" if ticket_count.to_i > department['danger_threshold']
send_event("sirportly_#{name}", { current: ticket_count, status: status })
end
end
rescue Errno::ENOENT
puts "No config file found for sirportly - not starting the Sirportly job"
end
departments:
dev:
team: Dev
domain: "http://sirportly.yourdmain.com"
api_token: "b374fe861234-2345-67854"
api_secret: "veryveryverylonghash"
statuses: ["New", "Waiting for Staff"]
warning_threshold: 10
danger_threshold: 20
support:
team: Support
domain: "http://sirportly.com"
api_token: "hjskahdkjsahdjkadhjkdhajskdhj"
api_secret: "sadasdsaadsadsadsdsaddsasd"
statuses: ["New", "Waiting for Staff"]
warning_threshold: 5
danger_threshold: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment