Created
July 7, 2013 08:35
-
-
Save mikeda/5942806 to your computer and use it in GitHub Desktop.
Nagiosの通知をGoogleスプレッドシートに書き込むサンプル
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
| 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 | |
| } |
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
| #!/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