Created
August 8, 2016 14:40
-
-
Save kylebrandt/38c9fdef155f7fa9ac840207f886be43 to your computer and use it in GitHub Desktop.
Bosun Puppet Example ( :: in fname is dir )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"classes": [ | |
"bosun", | |
], | |
"bosun::quiet": false, | |
"bosun::httplisten": ":8080", | |
"bosun::timeanddate": [ 202, 75, 179, 136 ], | |
"bosun::hostname": "bosun.example.com", | |
"bosun::shorturlkey": "2220abb99ef14ebaa2a9c12afd8185e1", | |
"bosun::rulefilepath": "/opt/bosun/config/prod.conf", | |
"bosun::checkfrequency": "1m", | |
"bosun::checkfrequency": 5, | |
"bosun::enablesave": true, | |
"bosun::ping": true, | |
"bosun::opentsdb": { | |
"host": "localhost:80", | |
"version":2.2, | |
"responselimit":25000000 | |
}, | |
"bosun::elastic":{ | |
"hosts": ["http://elastic01.example.com:9200","http://elastic02.example.com:9200","http://elastic03.example.com:9200","http://elastic04.example.com:9200","http://elastic05.example.com:9200","http://elastic06.example.com:9200"] | |
}, | |
"bosun::annotate":{ | |
"hosts": ["http://elastic01.example.com:9200","http://elastic02.example.com:9200","http://elastic03.example.com:9200","http://elastic04.example.com:9200","http://elastic05.example.com:9200","http://elastic06.example.com:9200"] | |
}, | |
"bosun::db":{ | |
"redishost" : "localhost:6389" | |
}, | |
"bosun::smtp": { | |
"from": "[email protected]", | |
"host": "mail.example.com:25" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# bosun | |
# | |
# chkconfig: - 98 02 | |
# description: bosun | |
### BEGIN INIT INFO | |
# Provides: bosun | |
# Required-Start: networking | |
# Required-Stop: networking | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Runs teh bosun | |
# Description: bosun | |
### END INIT INFO | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
base_dir="/opt/bosun" | |
exec="/opt/bosun/bosun" | |
prog="bosun" | |
config="${base_dir}/bosun.toml" | |
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog | |
lockfile=/var/lock/subsys/$prog | |
pidfile=/var/run/bosun.pid | |
logfile=/var/log/$prog.log | |
#These "secrets" can be used in the prod.conf using syntax like ${env.CHAT_SRE} | |
export CHAT_SAMPLEKEY=https://chat.example.com/feeds/rooms/123?key=2220abb9-9ef1-4eba-a2a9-c12afd8185e1 | |
check() { | |
$exec -t -c $config | |
if [ $? -ne 0 ]; then | |
echo "Errors found in configuration file, check it with '$exec -t'." | |
exit 1 | |
fi | |
} | |
start() { | |
[ -x $exec ] || exit 5 | |
[ -f $config ] || exit 6 | |
check | |
echo -n $"Starting $prog: " | |
# if not running, start it up here, usually something like "daemon $exec" | |
ulimit -n 65536 | |
daemon daemonize -a -c $base_dir -e $logfile -o $logfile -p $pidfile -l $lockfile $exec -c $config $OPTS | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && touch $lockfile | |
return $retval | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
# stop it here, often "killproc $prog" | |
killproc -p $pidfile -d 5m | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && rm -f $lockfile | |
return $retval | |
} | |
restart() { | |
check | |
stop | |
start | |
} | |
reload() { | |
restart | |
} | |
force_reload() { | |
restart | |
} | |
rh_status() { | |
# run checks to determine if the service is running or use generic status | |
status $prog | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
$1 | |
;; | |
stop) | |
rh_status_q || exit 0 | |
$1 | |
;; | |
restart) | |
$1 | |
;; | |
reload) | |
rh_status_q || exit 7 | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
status) | |
rh_status | |
;; | |
condrestart|try-restart) | |
rh_status_q || exit 0 | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | |
exit 2 | |
esac | |
exit $? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
class bosun ( | |
$quiet = false, | |
$readonly = false, | |
$hostname = undef, | |
$httplisten = undef, | |
$shorturlkey = undef, | |
$commandhookpath = undef, | |
$rulefilepath = undef, | |
$enablesave = undef, | |
$ping = undef, | |
$timeanddate = hiera_array('bosun::timeanddate', []), | |
$opentsdb = hiera_hash('bosun::opentsdb', {}), | |
$elastic = hiera_hash('bosun::elastic', {}), | |
$annotate = hiera_hash('bosun::annotate', {}), | |
$db = hiera_hash('bosun::db', {}), | |
$smtp = hiera_hash('bosun::smtp', {}), | |
) { | |
include bosun::install | |
if $quiet { | |
$qopt = '-q' | |
} else { | |
$qopt = '' | |
} | |
if $readonly { | |
$ropt = '-r' | |
} else { | |
$ropt = '' | |
} | |
$opts = "${qopt} ${ropt}" | |
#If we have saving enabled, then we need to turn off config pulling and | |
#turn on the command hook. The command hook is defaulted to ghook if we | |
#are not overriding it elswhere. | |
if $enablesave { | |
cron { 'gpull': | |
ensure => 'absent' | |
} | |
} else { | |
#Define a cron job to pull the config from git repo here | |
} | |
file { '/etc/sysconfig/bosun': | |
ensure => file, | |
mode => '0644', | |
owner => root, | |
group => root, | |
content => template('bosun/bosun.sysconfig.erb'), | |
notify => Service['bosun'], | |
} | |
file { '/opt/bosun/bosun.toml': | |
ensure => file, | |
mode => '0644', | |
owner => root, | |
group => root, | |
content => template('bosun/bosun.toml.erb'), | |
notify => Service['bosun'], | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
class bosun::install { | |
file { '/etc/init.d/bosun': | |
ensure => file, | |
mode => '0744', | |
owner => root, | |
group => root, | |
source => 'puppet:///modules/bosun/bosun.init' | |
} | |
service { 'bosun': | |
ensure => running, | |
enable => true, | |
require => [ File['/etc/init.d/bosun'] ] | |
} | |
#Dir where Bosun daemon will live | |
file { '/opt/bosun': | |
ensure => directory, | |
owner => svc_sadeploy, | |
group => svc_sadeploy, | |
require => Class['site::role_svc_sadeploy_login'], | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OPTS='<%= opts %>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%- if @hostname -%>Hostname = "<%= @hostname %>" | |
<%- end -%><%- if @httplisten -%>HTTPListen = "<%= @httplisten %>" | |
<%- end -%><%- if @timeanddate.any? -%>TimeAndDate = [<% @timeanddate.each_with_index do |v,i| -%><%- if i>0 -%>, <%- end -%><%= v %><% end -%>] | |
<%- end -%><%- if @shorturlkey -%>ShortURLKey = "<%= @shorturlkey %>" | |
<%- end -%><%- if @commandhookpath -%>CommandHookPath = "<%= @commandhookpath %>" | |
<%- end -%><%- if @rulefilepath -%>RuleFilePath = "<%= @rulefilepath %>" | |
<%- end -%><%- if @checkfrequency -%>CheckFrequency = "<%= @checkfrequency %>" | |
<%- end -%><%- if @defaultrunevery -%>DefaultRunEvery = <%= @defaultrunevery %> | |
<%- end -%>EnableSave = <%= @enablesave %> | |
Ping = <%= @ping %> | |
<%- if @opentsdb.any? -%> | |
[OpenTSDBConf] | |
Host = "<%= @opentsdb['host'] %>" | |
Version = <%= @opentsdb['version'] %> | |
ResponseLimit = <%= @opentsdb['responselimit'] %> | |
<%- end -%><%- if @elastic.any? -%> | |
[ElasticConf] | |
Hosts = [<% @elastic['hosts'].each_with_index do |v,i| -%><%- if i>0 -%>, <%- end -%>"<%= v %>"<% end -%>] | |
<%- end -%><%- if @db -%> | |
[DBConf] | |
RedisHost = "<%= @db['redishost'] %>" | |
<% end -%><%- if @smtp.any? -%> | |
[SMTPConf] | |
EmailFrom = "<%= @smtp['from'] %>" | |
Host = "<%= @smtp['host'] %>" | |
<% end -%><%- if @annotate.any? -%> | |
[AnnotateConf] | |
Hosts = [<% @annotate['hosts'].each_with_index do |v,i| -%><%- if i>0 -%>, <%- end -%>"<%= v %>"<% end -%>] | |
<% end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment