UbuntuMagazine7を参考にした覚書。
以下は監視対象サーバをUbuntuServer10.04LTSで実施しています。UbuntuServer以外では試してはいないが、PythonとTweepyが入れば行けるかも。
必要なモジュールのインストールを行う。
# apt-get update # apt-get upgrade # apt-get install python-setuptools # easy_install tweepy
以下のスクリプト「
get_timeline.py」実行により環境に問題ないか確認可能。
#! /usr/bin/env python
import tweepy
tweets = tweepy.api.public_timeline()
for tweet in tweets:
print tweet.text
以下のコマンドラインで実行を行う。
$ python ./get_timeline.py
上記のコマンドは、世界中の最新ツイートが20件表示されるスクリプト。正しく、表示されていればOK。
Application details ・Name: <applications名> ・Description: <applicationsの詳細> ・WebSite: https://twitter.com/#!/<アカウント名> ・Callback URL: <空白>
My applicationsから上記で作成したものを選択し、Detailsの以下の項目をメモ。 ・[OAuth settings]-[Consumer key] ・[OAuth settings]-[Consumer secret] ・[Your access token]-[Access token] ・[Your access token]-[Access token secret]
ツイートする場合にはスクリプト「
stdinput_tw.py」を使用、ダイレクトメールを使用する場合にはスクリプト「
stdinput_dm.py」を使用する。
tail -f foo.log | python stdinput_dm.py
ただし、気を付けてほしい。通常のログから発報させるためには、それなりにフィルタリングしてからじゃないと。