跳至內容
阿里BaBa電腦筆記
使用者工具
登入
網站工具
工具
顯示頁面
舊版
反向連結
最近更新
多媒體管理器
網站地圖
登入
最近更新
多媒體管理器
網站地圖
足跡:
linux:monitor:zabbix_alert
本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。
======利用google api calendar 發送SMS====== 因為發送訊息,是以python程式寫成。運用Google API Calendar等工具將信息傳到Google日曆,再利用Google日曆提供手機簡訊提醒工具來達成SMS的目的。 =====安裝===== 安裝python必要套件。 (easy_install )<code>#yum install python-setuptools</code><code>#easy_install python-gflags #easy_install httplib2 #easy_install argparse #easy_install rfc3339 #easy_install google-api-python-client</code> =====申請使用Google API金鑰===== 因為是使用Google API,需要到 https://code.google.com/apis/console/ (使用google帳號登入)申請API金鑰。 - 先到 service 開啟 calendar api (舊版控制台){{:linux:monitor:api_services.png?700|}} - 再到 API Access, 就可以找到程式所需的資訊(舊版控制台)。分別是Client ID: Client secret: API key:等項目{{:linux:monitor:api_apiaccess.png?300|}} - 用python撰寫 發送訊息到API的程式<code>#!/usr/bin/python # -*- coding: utf8 -*- import gflags import httplib2 import sys import time from apiclient.discovery import build from oauth2client.file import Storage from oauth2client.client import OAuth2WebServerFlow from oauth2client.tools import run from rfc3339 import rfc3339 FLAGS = gflags.FLAGS FLOW = OAuth2WebServerFlow( client_id='Your Client ID', client_secret='Your Client secret', scope='https://www.googleapis.com/auth/calendar', user_agent='APIProject/0.1') # To disable the local server feature, uncomment the following line: gflags.FLAGS.auth_local_webserver = False # If the Credentials don't exist or are invalid, run through the native client # flow. The Storage object will ensure that if successful the good # Credentials will get written back to a file. storage = Storage('/var/lib/zabbixsrv/alertscripts/calendar.dat') ==>(網址進行授權完成後,會在此路徑下產生calendar.dat) credentials = storage.get() if credentials is None or credentials.invalid == True: credentials = run(FLOW, storage) # Create an httplib2.Http object to handle our HTTP requests and authorize it # with our good Credentials. http = httplib2.Http() http = credentials.authorize(http) # Build a service object for interacting with the API. Visit # the Google APIs Console # to get a developerKey for your own application. service = build(serviceName='calendar', version='v3', http=http, # developerKey='AIzaSyDxuNerp7zgFl7Ing28YaceYfEcAToPLJw') developerKey='AIzaSyDAs0tCUXoPdBufmYbnfTtzv_2nY_TuOZc') #zb_sendto = 日曆ID ,zb_title = 主旨 , zb_body= 說明 zb_sendto= sys.argv[1] zb_title= sys.argv[2] zb_body= sys.argv[3] sttime = time.time() endtime = time.time()+60*60 event = { 'summary': zb_title, 'location': 'QY_office', 'description': zb_body, 'start': { 'dateTime': rfc3339(sttime), 'timeZone': 'Asia/Taipei' }, 'end': { 'dateTime': rfc3339(endtime), 'timeZone': 'Asia/Taipei' }, "reminders": { "useDefault": False, "overrides": [ { "method": "email", "minutes": 0 }, { "method": "popup", "minutes": 0 }, { "method": "sms", "minutes": 0 }, ] }, } created_event = service.events().insert(calendarId=zb_sendto, body=event).execute() print created_event['id'] </code>
linux/monitor/zabbix_alert.1395584073.txt.gz
· 上一次變更: 2014/03/23 14:14 由
ali88
頁面工具
顯示頁面
舊版
反向連結
回到頁頂