├── .gitignore
├── Procfile
├── views
├── index.erb
├── hostedit.erb
├── layout.erb
└── hostlist.erb
├── Capfile
├── scripts
├── etc
│ └── yasi.yml
├── init.d
│ ├── thin
│ └── selenium
├── bin
│ ├── yasi-cli.sh
│ └── cacti-cli.sh
├── yasi-cli.sh
├── yasi-cli.rb
└── cacti-cli.sh
├── Rakefile
├── Gemfile
├── config.ru
├── main.rb
├── README.md
├── resque.god
├── History.md
├── lib
├── helpers.rb
├── nagiosql2_debug.rb
└── nagiosql.rb
└── public
├── js
└── bootstrap-dropdown.js
└── css
└── yasi.css
/.gitignore:
--------------------------------------------------------------------------------
1 | release.sh
2 | config/*
3 | tmp/
4 | .*.swp
5 | .rvmrc
6 | .DS_Store
7 | vendor/*
8 |
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | web: bundle exec shotgun -s thin config.ru -E production
2 | #web: bundle exec thin start -R config.ru -e development -p 9393
3 | #worker: bundle exec rake resque:work QUEUE=*
4 |
--------------------------------------------------------------------------------
/views/index.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
×
4 |
Information: Metrics are being cooked.
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Capfile:
--------------------------------------------------------------------------------
1 | load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2 |
3 | # Uncomment if you are using Rails' asset pipeline
4 | # load 'deploy/assets'
5 |
6 | Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
7 |
8 | ## load 'config/deploy' # remove this line to skip loading any of the default tasks
9 |
--------------------------------------------------------------------------------
/scripts/etc/yasi.yml:
--------------------------------------------------------------------------------
1 | user: www-data
2 | group: www-data
3 | pid: /var/run/thin.pid
4 | timeout: 30
5 | wait: 30
6 | log: /var/log/thin.log
7 | max_conns: 1024
8 | require: []
9 | environment: development
10 | max_persistent_conns: 512
11 | servers: 1
12 | threaded: true
13 | no-epoll: true
14 | daemonize: true
15 | chdir: /servers/yasi
16 | tag: yasi-0.0.4
17 | address: localhost
18 | port: 9393
19 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'bundler/setup'
2 | Bundler.require(:default)
3 |
4 | require File.dirname(__FILE__) + "/main.rb"
5 | require File.dirname(__FILE__) + "/lib/nagiosql.rb"
6 |
7 | require 'resque/tasks'
8 |
9 | desc "resque Worker"
10 | task "resque:setup" do
11 | ENV['QUEUE'] = '*'
12 |
13 | Resque.redis = Redis.new( :host => 'localhost',
14 | :port => 6379,
15 | :thread_safe => true )
16 | end
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'http://rubygems.org'
2 | gem 'rack'
3 | gem 'rack-protection'
4 | gem 'sinatra', :require => 'sinatra/base'
5 | gem 'sinatra-contrib'
6 | gem 'mongoid'
7 | gem 'bson'
8 | gem 'bson_ext'
9 | gem 'selenium', :require => 'selenium/server'
10 | gem 'selenium-webdriver'
11 | gem 'resque', :require => 'resque/server'
12 | gem 'logger'
13 | gem 'foreman'
14 | gem 'thin'
15 | gem 'shotgun'
16 |
17 | gem 'pry-padrino'
18 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | require 'bundler/setup'
2 | Bundler.require(:default)
3 |
4 | require File.dirname(__FILE__) + "/main.rb"
5 | require File.dirname(__FILE__) + "/lib/nagiosql.rb"
6 |
7 | $stdout.sync = true
8 |
9 | use Rack::ShowExceptions
10 |
11 | use Rack::Auth::Basic, "Restricted Area" do |username, password|
12 | [username, password] == ['USER', 'PASS']
13 | end
14 |
15 |
16 | map('/') { run Yasi::Main }
17 |
18 | map('/nagiosql') { run Yasi::Nagiosql::Main }
19 |
20 | Resque.redis = Redis.new( :host => 'localhost',
21 | :port => 6379,
22 | :thread_safe => true )
23 |
24 | map('/resque') { run Resque::Server }
--------------------------------------------------------------------------------
/main.rb:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 | require File.dirname(__FILE__) + "/lib/helpers.rb"
3 |
4 | module Yasi
5 |
6 | class Main < Sinatra::Base
7 |
8 | use Yasi::Confs::MyCfg
9 | helpers Yasi::CommonHelpers
10 |
11 | error do
12 | e = request.env['sinatra.error']
13 | Kernel.puts e.backtrace.join("\n")
14 | "Application Error"
15 | end
16 |
17 | not_found do
18 | "Not found!"
19 | end
20 |
21 | # BEFORE FILTERS
22 |
23 | before do
24 | headers 'Content-Type' => 'text/html; charset=utf-8'
25 | end
26 |
27 | # CONTROLLERS
28 |
29 | get '/' do
30 | erb :index
31 | end
32 |
33 | end
34 |
35 | end
36 |
--------------------------------------------------------------------------------
/scripts/init.d/thin:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | ### BEGIN INIT INFO
3 | # Provides: thin
4 | # Required-Start: $local_fs $remote_fs
5 | # Required-Stop: $local_fs $remote_fs
6 | # Default-Start: 2 3 4 5
7 | # Default-Stop: S 0 1 6
8 | # Short-Description: thin initscript
9 | # Description: thin
10 | ### END INIT INFO
11 |
12 | # Original author: Forrest Robertson
13 |
14 | # Do NOT "set -e"
15 |
16 | rvm use 1.9.2@sin
17 |
18 | DAEMON=/usr/local/rvm/gems/ruby-1.9.2-p290@sin/bin/thin
19 | SCRIPT_NAME=/etc/init.d/thin
20 | CONFIG_PATH=/servers/etc/thin
21 |
22 | # Exit if the package is not installed
23 | [ -x "$DAEMON" ] || exit 0
24 |
25 | case "$1" in
26 | start)
27 | $DAEMON start --all $CONFIG_PATH
28 | ;;
29 | stop)
30 | $DAEMON stop --all $CONFIG_PATH
31 | ;;
32 | restart)
33 | $DAEMON restart --all $CONFIG_PATH
34 | ;;
35 | *)
36 | echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
37 | exit 3
38 | ;;
39 | esac
40 |
41 | :
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **YASI** - Yet Another Stupid Idea
2 |
3 | This software acts as a glue between Puppet and Nagios while managed through NagiosQL.
4 |
5 |
6 | Under Puppet you must build a class as:
7 |
8 | define yasi_monit($ostype) {
9 |
10 | case $ostype {
11 | /(linux|freebsd)/: {
12 | exec { 'conf_nagios_cacti':
13 | command => "/servers/scripts/system/hosts/global/yasi-cli.sh addhost $::hostname $::ipaddress $::fqdn default \'linux default\'",
14 | }
15 | }
16 |
17 | /windows/: {
18 | exec { 'conf_nagios_cacti':
19 | path => $::path,
20 | command => "cmd.exe /c ruby C:\\servers\\scripts\\system\\hosts\\global\\yasi-cli.rb addhost $::hostname $::ipaddress ${::hostname}.%USERDNSDOMAIN% default \'windows default\' snmpmaster",
21 | }
22 | }
23 | }
24 | }
25 |
26 | Host manifests must be registered as:
27 |
28 | exec { "conf_nagios_cacti":
29 | command => "/servers/scripts/system/hosts/global/yasi-cli.sh addhost $::hostname $::ipaddress_be $::fqdn webservers \'webservers staging\'",
30 | schedule => 'daily'
31 | }
32 |
33 | (readme)… to be continued
--------------------------------------------------------------------------------
/views/hostedit.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | | Hostname |
7 | Address |
8 | FQDN |
9 | Hostgroup |
10 | Hostgroup desc |
11 | Status |
12 | |
13 |
14 |
15 |
16 |
17 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/resque.god:
--------------------------------------------------------------------------------
1 | God.watch do |w|
2 | w.name = 'resque'
3 | w.interval = 30.seconds
4 | w.env = { 'RACK_ENV' => 'production', 'QUEUE' => '*' }
5 | w.uid = 'nagiosmaster'
6 | w.gid = 'nagiosmaster'
7 | #w.dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
8 | #w.start = "rake resque:work"
9 | w.start = "cd /servers/yasi && RACK_ENV=production rake resque:work"
10 | w.start_grace = 10.seconds
11 | w.log = File.expand_path(File.join(File.dirname(__FILE__), 'log','resque-worker.log'))
12 |
13 | # restart if memory gets too high
14 | w.transition(:up, :restart) do |on|
15 | on.condition(:memory_usage) do |c|
16 | c.above = 200.megabytes
17 | c.times = 2
18 | end
19 | end
20 |
21 | # determine the state on startup
22 | w.transition(:init, { true => :up, false => :start }) do |on|
23 | on.condition(:process_running) do |c|
24 | c.running = true
25 | end
26 | end
27 |
28 | # determine when process has finished starting
29 | w.transition([:start, :restart], :up) do |on|
30 | on.condition(:process_running) do |c|
31 | c.running = true
32 | c.interval = 5.seconds
33 | end
34 |
35 | # failsafe
36 | on.condition(:tries) do |c|
37 | c.times = 5
38 | c.transition = :start
39 | c.interval = 5.seconds
40 | end
41 | end
42 |
43 | # start if process is not running
44 | w.transition(:up, :start) do |on|
45 | on.condition(:process_running) do |c|
46 | c.running = false
47 | end
48 | end
49 | end
--------------------------------------------------------------------------------
/scripts/bin/yasi-cli.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | # puppet-cli.sh Abstract curl
3 | # Version - 0.1
4 | # Date 9/12/2011 -
5 |
6 | DATE="$(date "+%Y%m%d%H")"
7 |
8 | ARGS=6
9 | E_BADARGS=65
10 |
11 | CURL_BIN="/usr/bin/curl"
12 | CURL_OPT="-i -d"
13 |
14 | YASI_HOST="localhost"
15 | YASI_PORT="9393"
16 | YASI_ADDHOST_URI="/nagiosql/c/host"
17 |
18 | ACTION=$1
19 | HOSTNAME=$2
20 | ADDRESS=$3
21 | FQDN=$4
22 | HOSTGROUP=$5
23 | HOSTGROUPDESC=$6
24 |
25 | function help {
26 | echo ""
27 | echo "Usage:"
28 | echo " yasi-cli.sh help"
29 | echo " yasi-cli.sh addhost hostname ip fqdn hostgroup hostgroupdesc"
30 | echo ""
31 | echo "Example:"
32 | echo " ./yasi-cli.sh addhost lolcat 127.0.0.1 lolcat.domain.tld lolcats \"lolcats servers\""
33 | echo ""
34 | }
35 |
36 | function addhost {
37 |
38 | if [ -z ${HOSTNAME} ]; then
39 | echo "Insert hostname please!"
40 | exit 1;
41 | elif [ -z ${ADDRESS} ]; then
42 | echo "Insert address please!"
43 | exit 1;
44 | elif [ -z ${FQDN} ]; then
45 | echo "Insert FQDN please!"
46 | exit 1;
47 | elif [ -z ${HOSTGROUP} ]; then
48 | echo "Insert hostgroup"
49 | exit 1;
50 | elif [ -z "${HOSTGROUPDESC}" ]; then
51 | echo "Insert hostgroup description"
52 | exit 1;
53 | fi
54 |
55 | # curl -i -d "hostname=lolcat&address=127.0.0.1&fqdn=lolcat.domain.tld&hostgroup=lolcat&hostgroupdesc=my%20sweet" http://nagios3:9393/nagiosql/c/host
56 |
57 | # change spaces into %20
58 | HOSTGROUPDESC_CLEAN="$(echo ${HOSTGROUPDESC} | sed 's/ /%20/g')"
59 |
60 | YASI_ADDHOST_PAYLOAD="hostname=${HOSTNAME}&address=${ADDRESS}&fqdn=${FQDN}&hostgroup=${HOSTGROUP}&hostgroupdesc=${HOSTGROUPDESC_CLEAN}"
61 |
62 | ${CURL_BIN} ${CURL_OPT} "${YASI_ADDHOST_PAYLOAD}" http://${YASI_HOST}:${YASI_PORT}/${YASI_ADDHOST_URI}
63 |
64 | }
65 |
66 |
67 | case "${ACTION}" in
68 | "addhost" ) addhost ;;
69 | "help" | "" | * ) help exit 0 ;;
70 | esac
71 |
--------------------------------------------------------------------------------
/views/layout.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 | YASI
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | <%= yield %>
59 |
60 |
61 |
62 |
63 |
64 |