Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Last active August 29, 2015 14:05
Show Gist options
  • Save tolleiv/d7ab8e1611330e0fdf76 to your computer and use it in GitHub Desktop.
Save tolleiv/d7ab8e1611330e0fdf76 to your computer and use it in GitHub Desktop.
Zabbix Info Widget

Zabbix Info Widget

This is a Dashing widget and all components needed to outline some general Zabbix server numbers.

##Usage

To use this widget, copy zabbix_info.html, zabbix_info.coffee, and zabbix_info.scss into the /widgets/zabbix_info directory. Put the zabbix_info.rb file in your /jobs folder. Or simply run dashing install d7ab8e1611330e0fdf76 to let dashing do that for you.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

 <li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
   <div data-id="zabbix_info" data-view="ZabbixInfo"></div>
 </li>

##Settings

To provide access from the job to the Zabbix API you've to create a user within Zabbix and place the credentials within a separate file (zabbix_credentials.rb) in the dashing root folder. The content should look like:

 module ZabbixCredentials
   SERVER = 'https://zabbix.example.com/api_jsonrpc.php'
   USERNAME = 'zabbix_user'
   PASSWORD = 'zabbix_password'
 end

##Preview Zabbix Info Dashing Widget

class Dashing.ZabbixInfo extends Dashing.Widget
ready: ->
# Nothing
<h1 class="title" data-bind="title"></h1>
<ul>
<li data-foreach-item="items">
<span class="label" data-bind="item.label"></span>
<span class="value" data-bind="item.value"></span>
</li>
</ul>
<p class="more-info" data-bind="moreinfo"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'zabby'
require 'json'
require 'active_support/core_ext/numeric/time'
require_relative '../zabbix_credentials'
# Encapsulates the count queries
class Zabbix
def initialize
@serv = Zabby.init do
set server: ZabbixCredentials::SERVER
set user: ZabbixCredentials::USERNAME
set password: ZabbixCredentials::PASSWORD
login
end
end
def pass(name, &block)
count = @serv.run(&block)
{ label: name, value: count }
end
end
SCHEDULER.every '15m' do
z = Zabbix.new
facts = []
facts.push(z.pass('Hosts') { Zabby::Host.get('countOutput' => 1) })
facts.push(z.pass('Maintenances') { Zabby::Maintenance.get('countOutput' => 1) })
# facts.push(z.pass('Events') { Zabby::Event.get('countOutput' => 1, 'hide_unknown' => 1, 'acknowledged' => 0) })
facts.push(z.pass('Items') { Zabby::Item.get('countOutput' => 1) })
facts.push(z.pass('Applications') { Zabby::Application.get('countOutput' => 1) })
facts.push(z.pass('Triggers') { Zabby::Trigger.get('countOutput' => 1) })
facts.push(z.pass('Templates') { Zabby::Template.get('countOutput' => 1) })
send_event('zabbix_info', items: facts)
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #4F7383;
//$background-color: rgba(0,0,0, 0.3);
$value-color: #fff;
$label-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-list styles
// ----------------------------------------------------------------------------
.widget.widget-zabbix-info {
vertical-align: bottom;
background-color: $background-color;
padding:12px 12px;
ul {
text-align: left;
color: $label-color;
font-size:16px;
margin-bottom: 30px;
}
li {
margin-bottom: 5px;
}
.list-nostyle {
list-style: none;
}
.label {
color: $label-color;
}
.value {
float: right;
margin-left: 12px;
font-weight: 600;
color: $value-color;
}
.updated-at {
// color: rgba(0, 0, 0, 0.3);
}
.more-info {
color: $moreinfo-color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment