Skip to content

Instantly share code, notes, and snippets.

@michthom
Forked from welsh/README.md
Last active November 14, 2017 15:35
Show Gist options
  • Save michthom/e70bb7f4f4c74c8350ce to your computer and use it in GitHub Desktop.
Save michthom/e70bb7f4f4c74c8350ce to your computer and use it in GitHub Desktop.

Revisions

  1. michthom revised this gist May 24, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ I've extended it a little to offer more types of connectivity test, and to be a

    Description
    ===========
    The widget updates the appropriate squares color upon determining its status. Statuses are as follows:
    The widget updates the appropriate squares color upon determining its status. Default statuses are shown as follows:

    * Blue represents a new square that hasn't had any data sent to it yet.
    * Green represents that the square is responding properly
  2. michthom revised this gist May 24, 2015. 1 changed file with 17 additions and 15 deletions.
    32 changes: 17 additions & 15 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,10 @@ Server Status Squares
    ===========
    A [Dashing](https://github.com/Shopify/dashing) widget that checks whether a server is responding to either an http or ping request using smaller squares to represent its status.

    This is based off of the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed.
    This is based on the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed.

    [welsh](https://gist.github.com/welsh/9588819) modified it to work across multiple squares rather than be one square with a list.

    I've extended it a little to offer more types of connectivity test, and to be a little more flexible in how success / errors are reflected back to the user.

    Description
    @@ -18,28 +20,28 @@ Example:

    ![](http://i.imgur.com/z60zdxI.png)

    Setup - Manual
    Setup - Auto
    =====
    1. Move `server_status_squares.erb` into your `dashboards` directory.

    2. Create a directory called `server_status_squares` under your `widgets` directory and move the following under it:
    * `server_status_squares.coffee`
    * `server_status_squares.html`
    * `server_status_squares.scss`
    1. Within your dashing project do `dashing install e70bb7f4f4c74c8350ce`

    3. Move `server_status_squares.rb` into your `jobs` directory.
    2. Create a new file `server_status_squares.erb` in your `dashboards` directory. See the example below.

    4. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show this example dashboard:
    3. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show the example dashboard.

    ![](http://i.imgur.com/WQ85Cvr.png)

    Setup - Auto
    Setup - Manual
    =====
    1. Within your dashing project do `dashing install e70bb7f4f4c74c8350ce`
    1. Copy the contents of `server_status_squares.erb` into your `dashboards` directory.

    2. Create a directory called `server_status_squares` under your `widgets` directory and copy the contents of the following files under it:
    * `server_status_squares.coffee`
    * `server_status_squares.html`
    * `server_status_squares.scss`

    2. Move `server_status_squares.erb` into your `dashboards` directory.
    3. Copy the contents of `server_status_squares.rb` into your `jobs` directory.

    3. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show the above example dashboard.
    4. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show this example dashboard:

    Adjusting
    =====
    @@ -55,7 +57,7 @@ Then in your `server_status_squares.rb` file within the `jobs` directory adjust

    You need to ensure that the `data-id` of the dashboard entry matches the `name` in the new `servers` array entry.

    I use the `sss-` prefix so I know its a Server Status Squares entry.
    The names are up to you. I use the `sss-` prefix so I know its a Server Status Squares entry.

    Notes
    =====
  3. michthom revised this gist May 23, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion myfile.erb
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    some text goes here
  4. michthom revised this gist May 23, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions myfile.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    some text goes here
  5. michthom revised this gist May 23, 2015. 3 changed files with 61 additions and 38 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ Setup - Manual

    Setup - Auto
    =====
    1. Within your dashing project do `dashing install 9588819`
    1. Within your dashing project do `dashing install e70bb7f4f4c74c8350ce`

    2. Move `server_status_squares.erb` into your `dashboards` directory.

    @@ -51,7 +51,7 @@ To add a new server, add the following into your dashboard:

    Then in your `server_status_squares.rb` file within the `jobs` directory adjust the `servers` array to add a new entry:

    {name: 'sss-mynewserver', url: '192.168.1.150', method: 'ping'},
    {name: 'sss-mynewserver', url: 'ping://192.168.1.150'},

    You need to ensure that the `data-id` of the dashboard entry matches the `name` in the new `servers` array entry.

    8 changes: 1 addition & 7 deletions server_status_squares.erb
    Original file line number Diff line number Diff line change
    @@ -19,13 +19,7 @@ $(function() {
    </li>

    <li data-row="1" data-col="3" data-sizex="1" data-sizey="1">
    <div data-id="sss-gateway" data-view="ServerStatusSquares" data-title="Gateway"></div>
    </li>
    <li data-row="1" data-col="4" data-sizex="1" data-sizey="1">
    <div data-id="sss-reddit" data-view="ServerStatusSquares" data-title="Reddit"></div>
    </li>
    <li data-row="1" data-col="5" data-sizex="1" data-sizey="1">
    <div data-id="sss-github" data-view="ServerStatusSquares" data-title="Github"></div>
    <div data-id="sss-gateway" data-view="ServerStatusSquares" data-title="Gateway"></div>
    </li>
    <li data-row="2" data-col="3" data-sizex="1" data-sizey="1">
    <div data-id="sss-brokenserver" data-view="ServerStatusSquares" data-title="Broken Server"></div>
    87 changes: 58 additions & 29 deletions server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/usr/bin/env ruby
    require 'net/http'
    require 'uri'
    require 'net/http'
    require 'net/telnet'

    #
    ### Global Config
    @@ -10,7 +11,7 @@
    #
    httptimeout = 60
    ping_count = 10

    #
    # Check whether a server is Responding you can set a server to
    # check via http request or ping
    @@ -29,48 +30,76 @@
    # the check will return false
    #
    servers = [
    {name: 'sss-gateway', url: '192.168.1.1', method: 'ping'},
    {name: 'sss-reddit', url: 'http://www.reddit.com/', method: 'http'},
    {name: 'sss-github', url: 'https://github.com/', method: 'http'},
    {name: 'sss-brokenserver', url: '192.168.1.100', method: 'ping'},
    {name: 'sss-gateway', url: 'ping://192.168.1.1' },
    {name: 'sss-google', url: 'http://google.co.uk' },
    {name: 'sss-gmail', url: 'telnet://smtp.gmail.com:565' },
    {name: 'sss-broken', url: 'http://1.2.3.4' }
    ]

    SCHEDULER.every '1m', :first_in => 0 do |job|
    servers.each do |server|
    if server[:method] == 'http'
    begin
    uri = URI.parse(server[:url])
    begin
    uri = URI.parse(server[:url])

    case uri.scheme

    when 'http'
    http = Net::HTTP.new(uri.host, uri.port)
    http.read_timeout = httptimeout
    response = Net::HTTP::get_response(uri)
    if response.is_a?(Net::HTTPError)
    result = 0
    else
    result = 1
    end

    when 'https'
    http = Net::HTTP.new(uri.host, uri.port)
    http.read_timeout = httptimeout
    if uri.scheme == "https"
    http.use_ssl=true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.use_ssl=true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    response = Net::HTTP::get_response(uri)
    if response.is_a?(Net::HTTPError)
    result = 0
    else
    result = 1
    end
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    if response.code == "200"

    when 'ping'
    result = `ping -q -c #{ping_count} #{uri.host}`
    if ($?.exitstatus == 0)
    result = 1
    else
    result = 0
    end
    rescue Timeout::Error
    result = 0
    rescue Errno::ETIMEDOUT
    result = 0
    rescue Errno::EHOSTUNREACH
    result = 0
    rescue Errno::ECONNREFUSED
    result = 0
    rescue SocketError => e

    when 'telnet'
    result = 0
    end
    elsif server[:method] == 'ping'
    result = `ping -q -c #{ping_count} #{server[:url]}`
    if ($?.exitstatus == 0)
    connection = Net::Telnet::new(
    "Host" => uri.host,
    "Port" => uri.port,
    "Timeout" => 5,
    "Telnetmode" => false
    )
    result = 1
    connection.close()

    else
    result = 0
    print "I have no idea how to handle URLs with a scheme of #{uri.scheme}\n"

    end

    rescue Timeout::Error
    result = 0
    rescue Errno::ETIMEDOUT
    result = 0
    rescue Errno::EHOSTUNREACH
    result = 0
    rescue Errno::ECONNREFUSED
    result = 0
    rescue SocketError => e
    result = 0

    end

    send_event(server[:name], result: result)
  6. michthom revised this gist May 23, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,9 @@ Server Status Squares
    ===========
    A [Dashing](https://github.com/Shopify/dashing) widget that checks whether a server is responding to either an http or ping request using smaller squares to represent its status.

    This is based off of the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed but modified to work across multiple squares rather than be one square with a list.
    This is based off of the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed.
    [welsh](https://gist.github.com/welsh/9588819) modified it to work across multiple squares rather than be one square with a list.
    I've extended it a little to offer more types of connectivity test, and to be a little more flexible in how success / errors are reflected back to the user.

    Description
    ===========
  7. @welsh welsh revised this gist Mar 26, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -57,6 +57,8 @@
    result = 0
    rescue Errno::ETIMEDOUT
    result = 0
    rescue Errno::EHOSTUNREACH
    result = 0
    rescue Errno::ECONNREFUSED
    result = 0
    rescue SocketError => e
  8. @welsh welsh revised this gist Mar 26, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -55,6 +55,8 @@
    end
    rescue Timeout::Error
    result = 0
    rescue Errno::ETIMEDOUT
    result = 0
    rescue Errno::ECONNREFUSED
    result = 0
    rescue SocketError => e
  9. @welsh welsh revised this gist Mar 19, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -55,6 +55,10 @@
    end
    rescue Timeout::Error
    result = 0
    rescue Errno::ECONNREFUSED
    result = 0
    rescue SocketError => e
    result = 0
    end
    elsif server[:method] == 'ping'
    result = `ping -q -c #{ping_count} #{server[:url]}`
  10. @welsh welsh revised this gist Mar 17, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,10 @@
    ### Global Config
    #
    # httptimeout => Number in seconds for HTTP Timeout. Set to ruby default of 60 seconds.
    # ping_count => Number of pings to perform for the ping method
    #
    httptimeout = 60
    ping_count = 10

    #
    # Check whether a server is Responding you can set a server to
    @@ -55,7 +57,6 @@
    result = 0
    end
    elsif server[:method] == 'ping'
    ping_count = 10
    result = `ping -q -c #{ping_count} #{server[:url]}`
    if ($?.exitstatus == 0)
    result = 1
  11. @welsh welsh revised this gist Mar 17, 2014. 1 changed file with 51 additions and 39 deletions.
    90 changes: 51 additions & 39 deletions server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -2,56 +2,68 @@
    require 'net/http'
    require 'uri'

    #
    ### Global Config
    #
    # httptimeout => Number in seconds for HTTP Timeout. Set to ruby default of 60 seconds.
    #
    httptimeout = 60

    #
    # Check whether a server is Responding you can set a server to
    # check via http request or ping
    #
    # Server Options
    # name
    # => The name of the Server Status Tile to Update
    # url
    # => Either a website url or an IP address. Do not include https:// when using ping method.
    # method
    # => http
    # => ping
    # name
    # => The name of the Server Status Tile to Update
    # url
    # => Either a website url or an IP address. Do not include https:// when using ping method.
    # method
    # => http
    # => ping
    #
    # Notes:
    # => If the server you're checking redirects (from http to https for example)
    # the check will return false
    # => If the server you're checking redirects (from http to https for example)
    # the check will return false
    #
    servers = [
    {name: 'sss-gateway', url: '192.168.1.1', method: 'ping'},
    {name: 'sss-reddit', url: 'http://www.reddit.com/', method: 'http'},
    {name: 'sss-github', url: 'https://github.com/', method: 'http'},
    {name: 'sss-brokenserver', url: '192.168.1.100', method: 'ping'},
    {name: 'sss-gateway', url: '192.168.1.1', method: 'ping'},
    {name: 'sss-reddit', url: 'http://www.reddit.com/', method: 'http'},
    {name: 'sss-github', url: 'https://github.com/', method: 'http'},
    {name: 'sss-brokenserver', url: '192.168.1.100', method: 'ping'},
    ]

    SCHEDULER.every '1m', :first_in => 0 do |job|
    servers.each do |server|
    if server[:method] == 'http'
    uri = URI.parse(server[:url])
    http = Net::HTTP.new(uri.host, uri.port)
    if uri.scheme == "https"
    http.use_ssl=true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    if response.code == "200"
    result = 1
    else
    result = 0
    end
    elsif server[:method] == 'ping'
    ping_count = 10
    result = `ping -q -c #{ping_count} #{server[:url]}`
    if ($?.exitstatus == 0)
    result = 1
    else
    result = 0
    end
    end
    servers.each do |server|
    if server[:method] == 'http'
    begin
    uri = URI.parse(server[:url])
    http = Net::HTTP.new(uri.host, uri.port)
    http.read_timeout = httptimeout
    if uri.scheme == "https"
    http.use_ssl=true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    if response.code == "200"
    result = 1
    else
    result = 0
    end
    rescue Timeout::Error
    result = 0
    end
    elsif server[:method] == 'ping'
    ping_count = 10
    result = `ping -q -c #{ping_count} #{server[:url]}`
    if ($?.exitstatus == 0)
    result = 1
    else
    result = 0
    end
    end

    send_event(server[:name], result: result)
    end
    send_event(server[:name], result: result)
    end
    end
  12. @welsh welsh revised this gist Mar 16, 2014. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ Example:

    ![](http://i.imgur.com/z60zdxI.png)

    Setup
    Setup - Manual
    =====
    1. Move `server_status_squares.erb` into your `dashboards` directory.

    @@ -31,6 +31,14 @@ Setup

    ![](http://i.imgur.com/WQ85Cvr.png)

    Setup - Auto
    =====
    1. Within your dashing project do `dashing install 9588819`

    2. Move `server_status_squares.erb` into your `dashboards` directory.

    3. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show the above example dashboard.

    Adjusting
    =====
    To add a new server, add the following into your dashboard:
    @@ -79,5 +87,4 @@ You can update it to show that is is up with:

    Or that it is down with:

    curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "result": 0 }' http://localhost:3030/widgets/sss-newserver

    curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "result": 0 }' http://localhost:3030/widgets/sss-newserver
  13. @welsh welsh revised this gist Mar 16, 2014. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -66,4 +66,18 @@ I've found that doing a `Dashing.widget_base_dimensions = [170, 170]` works best

    This can provide you a quick glance system to see if there are any issues with any of the servers as the Red Square will stand out in the sea (of hopefully) Green Squares.

    You can still create squares that are almost the same size as the Example dashboards base squares by setting `data-sizex="2" data-sizey="2"` for the `li` entry. You can see this in the `server_status_squares.erb` file for the Clock. (It will be shorter vertically by 30px.)
    You can still create squares that are almost the same size as the Example dashboards base squares by setting `data-sizex="2" data-sizey="2"` for the `li` entry. You can see this in the `server_status_squares.erb` file for the Clock. (It will be shorter vertically by 30px.)

    **API**<br/>
    To manually update the data of the widget, you can update via HTTP as described in the [Dashing Data](http://shopify.github.io/dashing/#data) section. To do this, find the `data-id` of the ServerStatusSquares widget and send it `"result": 1` if its up or `"result": 0` if its down.

    For example with the `server_status_squares` dashboard that was provided, the `New Server` square isn't hooked up to the `server_status_squares.rb` job.

    You can update it to show that is is up with:

    curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "result": 1 }' http://localhost:3030/widgets/sss-newserver

    Or that it is down with:

    curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "result": 0 }' http://localhost:3030/widgets/sss-newserver

  14. @welsh welsh revised this gist Mar 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ Server Status Squares
    ===========
    A [Dashing](https://github.com/Shopify/dashing) widget that checks whether a server is responding to either an http or ping request using smaller squares to represent its status.

    This is an expansion off of the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed.
    This is based off of the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed but modified to work across multiple squares rather than be one square with a list.

    Description
    ===========
  15. @welsh welsh revised this gist Mar 16, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -64,4 +64,6 @@ You can modify the `'60s'` to be any number for seconds. To configure it to 5 mi
    **Cube Sizing**<br/>
    I've found that doing a `Dashing.widget_base_dimensions = [170, 170]` works best to fit an optimal number of Squares on a 1080p Dashboard as you can do 10 across and 6 down for a total of 60 Squares.

    This can provide you a quick glance system to see if there are any issues with any of the servers as the Red Square will stand out in the sea (of hopefully) Green Squares.
    This can provide you a quick glance system to see if there are any issues with any of the servers as the Red Square will stand out in the sea (of hopefully) Green Squares.

    You can still create squares that are almost the same size as the Example dashboards base squares by setting `data-sizex="2" data-sizey="2"` for the `li` entry. You can see this in the `server_status_squares.erb` file for the Clock. (It will be shorter vertically by 30px.)
  16. @welsh welsh revised this gist Mar 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ Notes
    **Managing large number of servers**<br/>
    Depending on the number of squares you want to manage and the polling duration you may want to create multiple Server Status Squares jobs.

    For example if you have say 60 servers listed and it runs every 60 seconds you may run into issues with jobs beginning to overlap.
    For example if you have say 60 servers listed and it runs every 60 seconds you may run into issues with jobs overlapping.

    **Adjusting polling duration**<br/>
    To adjust the polling duration, open up the `server_status_squares.rb` job file and modify the main scheduler line which is currently set at 60 seconds. The line is:
  17. @welsh welsh revised this gist Mar 16, 2014. 2 changed files with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,9 @@ Then in your `server_status_squares.rb` file within the `jobs` directory adjust

    {name: 'sss-mynewserver', url: '192.168.1.150', method: 'ping'},

    You need to ensure that the `data-id` of the dashboard entry matches the `name` in the new `servers` array entry. I use the `sss-` prefix so I know its a Server Status Squares entry.
    You need to ensure that the `data-id` of the dashboard entry matches the `name` in the new `servers` array entry.

    I use the `sss-` prefix so I know its a Server Status Squares entry.

    Notes
    =====
  18. @welsh welsh revised this gist Mar 16, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -18,14 +18,14 @@ Example:

    Setup
    =====
    1. Create a file called `server_status_squares.erb` under your `dashboards` directory and move `server_status_squares.erb` into it.
    1. Move `server_status_squares.erb` into your `dashboards` directory.

    2. Create a directory called `server_status_squares` under your `widgets` directory and move the following under it:
    * `server_status_squares.coffee`
    * `server_status_squares.html`
    * `server_status_squares.scss`

    3. Create a file called `server_status_squares.rb` under your `jobs` directory and move `server_status_squares.erb` into it.
    3. Move `server_status_squares.rb` into your `jobs` directory.

    4. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show this example dashboard:

  19. @welsh welsh created this gist Mar 16, 2014.
    65 changes: 65 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    Server Status Squares
    ===========
    A [Dashing](https://github.com/Shopify/dashing) widget that checks whether a server is responding to either an http or ping request using smaller squares to represent its status.

    This is an expansion off of the [Server Status](https://gist.github.com/willjohnson/6313986) widget that [willjohnson](https://github.com/willjohnson) developed.

    Description
    ===========
    The widget updates the appropriate squares color upon determining its status. Statuses are as follows:

    * Blue represents a new square that hasn't had any data sent to it yet.
    * Green represents that the square is responding properly
    * Red represents that there is an issue. (Ping failed, non 200 response, etc.)

    Example:

    ![](http://i.imgur.com/z60zdxI.png)

    Setup
    =====
    1. Create a file called `server_status_squares.erb` under your `dashboards` directory and move `server_status_squares.erb` into it.

    2. Create a directory called `server_status_squares` under your `widgets` directory and move the following under it:
    * `server_status_squares.coffee`
    * `server_status_squares.html`
    * `server_status_squares.scss`

    3. Create a file called `server_status_squares.rb` under your `jobs` directory and move `server_status_squares.erb` into it.

    4. Run Dashing and navigate to [http://localhost:3030/server\_status\_squares](http://localhost:3030/server_status_squares) which will show this example dashboard:

    ![](http://i.imgur.com/WQ85Cvr.png)

    Adjusting
    =====
    To add a new server, add the following into your dashboard:

    <li data-row="2" data-col="4" data-sizex="1" data-sizey="1">
    <div data-id="sss-mynewserver" data-view="ServerStatusSquares" data-title="My Server"></div>
    </li>

    Then in your `server_status_squares.rb` file within the `jobs` directory adjust the `servers` array to add a new entry:

    {name: 'sss-mynewserver', url: '192.168.1.150', method: 'ping'},

    You need to ensure that the `data-id` of the dashboard entry matches the `name` in the new `servers` array entry. I use the `sss-` prefix so I know its a Server Status Squares entry.

    Notes
    =====
    **Managing large number of servers**<br/>
    Depending on the number of squares you want to manage and the polling duration you may want to create multiple Server Status Squares jobs.

    For example if you have say 60 servers listed and it runs every 60 seconds you may run into issues with jobs beginning to overlap.

    **Adjusting polling duration**<br/>
    To adjust the polling duration, open up the `server_status_squares.rb` job file and modify the main scheduler line which is currently set at 60 seconds. The line is:

    SCHEDULER.every '60s', :first_in => 0 do |job|

    You can modify the `'60s'` to be any number for seconds. To configure it to 5 minutes you can do `'5m'`.

    **Cube Sizing**<br/>
    I've found that doing a `Dashing.widget_base_dimensions = [170, 170]` works best to fit an optimal number of Squares on a 1080p Dashboard as you can do 10 across and 6 down for a total of 60 Squares.

    This can provide you a quick glance system to see if there are any issues with any of the servers as the Red Square will stand out in the sea (of hopefully) Green Squares.
    6 changes: 6 additions & 0 deletions server_status_squares.cofee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    class Dashing.ServerStatusSquares extends Dashing.Widget

    onData: (data) ->
    $(@node).fadeOut().fadeIn()
    color = if data.result == 1 then "#96BF48" else "#BF4848"
    $(@get('node')).css('background-color', "#{color}")
    37 changes: 37 additions & 0 deletions server_status_squares.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    <script type='text/javascript'>
    $(function() {
    Dashing.widget_base_dimensions = [170, 170]
    Dashing.numColumns = 10
    });
    </script>

    <% content_for :title do %>Status Status Squares<% end %>

    <div class="gridster">
    <ul>
    <li data-row="2" data-col="1" data-sizex="2" data-sizey="2">
    <div data-view="Clock" style="background-color: #4b4b4b"></div>
    <i class="icon-time icon-background"></i>
    </li>

    <li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
    <div data-id="welcome" data-view="Text" data-title="Server Status Squares" style="background-color: #4b4b4b"></div>
    </li>

    <li data-row="1" data-col="3" data-sizex="1" data-sizey="1">
    <div data-id="sss-gateway" data-view="ServerStatusSquares" data-title="Gateway"></div>
    </li>
    <li data-row="1" data-col="4" data-sizex="1" data-sizey="1">
    <div data-id="sss-reddit" data-view="ServerStatusSquares" data-title="Reddit"></div>
    </li>
    <li data-row="1" data-col="5" data-sizex="1" data-sizey="1">
    <div data-id="sss-github" data-view="ServerStatusSquares" data-title="Github"></div>
    </li>
    <li data-row="2" data-col="3" data-sizex="1" data-sizey="1">
    <div data-id="sss-brokenserver" data-view="ServerStatusSquares" data-title="Broken Server"></div>
    </li>
    <li data-row="2" data-col="4" data-sizex="1" data-sizey="1">
    <div data-id="sss-newserver" data-view="ServerStatusSquares" data-title="New Server"></div>
    </li>
    </ul>
    </div>
    3 changes: 3 additions & 0 deletions server_status_squares.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <h1 class="title" data-bind="title"></h1>

    <p class="updated-at" data-bind="updatedAtMessage"></p>
    57 changes: 57 additions & 0 deletions server_status_squares.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    #!/usr/bin/env ruby
    require 'net/http'
    require 'uri'

    #
    # Check whether a server is Responding you can set a server to
    # check via http request or ping
    #
    # Server Options
    # name
    # => The name of the Server Status Tile to Update
    # url
    # => Either a website url or an IP address. Do not include https:// when using ping method.
    # method
    # => http
    # => ping
    #
    # Notes:
    # => If the server you're checking redirects (from http to https for example)
    # the check will return false
    #
    servers = [
    {name: 'sss-gateway', url: '192.168.1.1', method: 'ping'},
    {name: 'sss-reddit', url: 'http://www.reddit.com/', method: 'http'},
    {name: 'sss-github', url: 'https://github.com/', method: 'http'},
    {name: 'sss-brokenserver', url: '192.168.1.100', method: 'ping'},
    ]

    SCHEDULER.every '1m', :first_in => 0 do |job|
    servers.each do |server|
    if server[:method] == 'http'
    uri = URI.parse(server[:url])
    http = Net::HTTP.new(uri.host, uri.port)
    if uri.scheme == "https"
    http.use_ssl=true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
    if response.code == "200"
    result = 1
    else
    result = 0
    end
    elsif server[:method] == 'ping'
    ping_count = 10
    result = `ping -q -c #{ping_count} #{server[:url]}`
    if ($?.exitstatus == 0)
    result = 1
    else
    result = 0
    end
    end

    send_event(server[:name], result: result)
    end
    end
    16 changes: 16 additions & 0 deletions server_status_squares.scss
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // ----------------------------------------------------------------------------
    // Widget Styles
    // ----------------------------------------------------------------------------
    .widget-server-status-squares {
    background-color: #12b0c5;
    vertical-align: top;

    .title {
    color: rgba(255, 255, 255, 0.7);
    font-size: 25px;
    }

    .updated-at {
    color: rgba(0, 0, 0, 0.3);
    }
    }