Checkman Simulator

This plugin reuses Checkman's configurations and plugins, so you don't need to install it :) It has checks for: HTTP, GoCD, Concourse, Jenkins, Travis, Semaphore, Codeship, CircleCI, Airbrake, GitHub, Pivotal Tracker, TDDium and SnapCI, and you can even create your own plugins to leverage Checkman's streamlined UI and configuration files. More info: https://gist.github.com/deluan/3f6fa6bcff2a355ae89181bb15590b88#file-readme-md

Image preview of Checkman Simulator plugin.

checkman.10s.rb

Edit
Open on GitHub
#!/usr/bin/env ruby

# <xbar.title>Checkman Simulator</xbar.title>
# <xbar.version>v0.1.1</xbar.version>
# <xbar.author>Deluan Quintao</xbar.author>
# <xbar.author.github>deluan</xbar.author.github>
# <xbar.desc>This plugin reuses Checkman's configurations and plugins, so you don't need to install it :) It has checks for: HTTP, GoCD, Concourse, Jenkins, Travis, Semaphore, Codeship, CircleCI, Airbrake, GitHub, Pivotal Tracker, TDDium and SnapCI, and you can even create your own plugins to leverage Checkman's streamlined UI and configuration files. More info: https://gist.github.com/deluan/3f6fa6bcff2a355ae89181bb15590b88#file-readme-md</xbar.desc>
# <xbar.image>http://i.imgur.com/irmlsOX.jpg</xbar.image>
# <xbar.dependencies>ruby</xbar.dependencies>
# <xbar.abouturl>https://goo.gl/SdNXj2</xbar.abouturl>

# This plugin simulates Checkman functionality, allowing you to use all its
# plugins and creating checks in external files. It downloads Checkman's plugins
# on demand, so you don't need to install Checkman itself.
#
# To learn more about Checkman, and learn about its existing plugins, see:
# https://github.com/cppforlife/checkman#included-check-scripts
#
# Configuration
# Same as for Checkman: https://github.com/cppforlife/checkman#configuring-checkman-via-checkfiles
#
# Missing/Not yet implemented:
# - Notifications/Stickies

require 'json'
require 'fileutils'
require 'open-uri'

CHECKS_DIR="#{ENV['HOME']}/.bitbar-checkman-plugins/"
CHECKS_URL="https://raw.githubusercontent.com/cppforlife/checkman/master/scripts/"
CONFIG_DIR="#{ENV['HOME']}/Checkman/"

README_URL="https://goo.gl/SdNXj2"

ICON_OK="iVBORw0KGgoAAAANSUhEU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vo/psjDcqyFPAN3iN3Op2+J0lyiM0ZuivbnUT+T5t0ozDPc7Nare5Go9G94jgMXIYrnOwQzifItj0gYuSg2Rw5Q0bj8fiZ9U9rAuOyymXbswAAAABJRU5ErkJggg=="

ICONS = {
  true: {
    false: ICON_OK,
    true: ICON_OK_CHANGING
  },
  false: {
    false: ICON_FAIL,
    true: ICON_FAIL_CHANGING
  },
}

PRIORITY_ORDER = [ICON_OK, ICON_OK_CHANGING, ICON_FAIL, ICON_FAIL_CHANGING, ICON_UNDETERMINED, ICON_UNDETERMINED_CHANGING]

DARK_MODE=`defaults read -g AppleInterfaceStyle 2> /dev/null`.strip
NO_DIM = " color=#{DARK_MODE == 'Dark' ? 'white' : 'black'} "

@output = ""
@failed = 0
@undetermined = 0
@aggregated_status = ICON_OK

def help
  puts " | image=#{ICON_UNDETERMINED}"
  puts "---"
  puts "Checkman Simulator v0.1.1|href=#{README_URL}"
  puts "More info...|href=#{README_URL}"
  puts "---"
  puts "No configuration files found in #{CONFIG_DIR} | bash=/usr/bin/open param1=\"#{CONFIG_DIR}\" terminal=false"
  puts "Click here to learn how to write configuration files... | href=https://github.com/cppforlife/checkman#configuring-checkman-via-checkfiles"
  puts "---\nRefresh... | refresh=true"
  exit
end

def plugin_path(plugin)
  FileUtils.mkdir_p(CHECKS_DIR)
  plugin_path = "#{CHECKS_DIR}/#{plugin}"
  return plugin_path if File.executable? plugin_path
  File.write(plugin_path, open("#{CHECKS_URL}/#{plugin}").read)
  File.chmod(0755, plugin_path)
  plugin_path
end

def format_info(info)
  lines = info[1].split("\n")
  s = "--#{info[0]}: #{lines[0]} | #{NO_DIM}"
  lines.each_with_index do |line, i|
    s += "\n--#{line} | #{NO_DIM}" if i > 0 
  end
  s += "href=#{info[1]}" if info[0].downcase == "url"
  s += "\n"
end

def parse_output(check_name, check_output)
  if check_output.strip == ""
    @output += "#{check_name}| #{NO_DIM} image= #{ICON_UNDETERMINED} \n"
    @undetermined += 1
    return ICON_UNDETERMINED
  end
  r = JSON.parse(check_output)
  icon = ICONS[r["result"].to_s.to_sym][(!!r["changing"]).to_s.to_sym]
  @output += "#{check_name}| image=#{icon} "
  @output += r['url'].nil? ? NO_DIM : "href=#{r['url']}"
  @output += "\n"
  @failed += 1 unless r["result"]
  unless r["info"].nil?
    r["info"].each do |i|
      if i[0] != '-'
        @output += format_info i
      else
        @output += "-----\n"
      end
    end
  end

  icon
end

check_files = Dir["#{CONFIG_DIR}/*"]
help if check_files.count == 0

check_files.each do |checkfile|
  check = File.open(checkfile).read
  check.each_line do |line|
    case line.strip
    when /^#-(.+)/
      @output += "#{$1.strip}| size=12\n"
    when '#-'
      @output += "---\n"
    when /^#.*/, ''
      true
    else
      item = line.split(":", 2)
      cmd = item[1].strip.split(" ", 2)
      output = `(#{plugin_path cmd[0]} #{cmd[1]}) 2>/dev/null`
      icon = parse_output item[0], output
      if PRIORITY_ORDER.index(icon) > PRIORITY_ORDER.index(@aggregated_status)
        @aggregated_status = icon
      end
    end
  end
  @output += "---\n"
end

if @undetermined > 0
  print @undetermined
elsif @failed > 0
    print @failed
end
puts " | image=#{@aggregated_status}"
puts "---\n#{@output}"

puts "---\nRefresh... | refresh=true"