Skip to content

Instantly share code, notes, and snippets.

@mikeda
Created July 7, 2013 08:35
Show Gist options
  • Select an option

  • Save mikeda/5942806 to your computer and use it in GitHub Desktop.

Select an option

Save mikeda/5942806 to your computer and use it in GitHub Desktop.
Nagiosの通知をGoogleスプレッドシートに書き込むサンプル
define command{
command_name notify-service-by-spreadsheet
command_line /etc/nagios/notify-service-by-spreadsheet.rb "$HOSTALIAS$" "$SERVICESTATE$" "$NOTIFICATIONTYPE$" "$SERVICEDESC$" "$SERVICEOUTPUT$" "$TIMET$"
}
define contact{
name generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-email,notify-service-by-spreadsheet
host_notification_commands notify-host-by-email
register 0
}
#!/usr/local/bin/ruby
# -*- coding: utf-8 -*-
#TODO:排他制御
require 'google_drive'
# HOSTNAME, HOSTSTATE, NOTIFICATIONTYPE, SERVICEDESC, HOSTOUTPUT, TIMET
host, state, type, desc, info, timestamp = ARGV
headers = %w(Time Host State Type Desc Info)
timestamp = timestamp.to_i
ss_title = 'nagios_alert'
ws_title = Time.at(timestamp).strftime("%Y-%m")
session = GoogleDrive.login("<user>@gmail.com", "<password>")
ss = session.spreadsheet_by_title(ss_title) || session.create_spreadsheet(ss_title)
ws = ss.worksheet_by_title(ws_title)
unless ws
ws = ss.add_worksheet(ws_title)
headers.each.with_index do |header, i|
ws[1, i+1] = header
end
end
num_row = ws.num_rows + 1
ws[num_row, 1] = Time.at(timestamp).strftime("%Y/%m/%d %H:%M:%S")
ws[num_row, 2] = host
ws[num_row, 3] = state
ws[num_row, 4] = type
ws[num_row, 5] = desc
ws[num_row, 6] = info
ws.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment