subprocess check_output , check kyototycoon

http://docs.python.org/2/library/subprocess.html#replacing-older-functions-with-the-subprocess-module

nagios用のスクリプト
pythonからktremotemgrを呼んで状態を確認する

2.6なのでcheck_outputが使えなかった

http://docs.python.org/2.6/library/subprocess.html#module-subprocess

popenのところだけ

from subprocess import Popen,PIPE

# 略

p = Popen(["ktremotemgr","report","-host",options.hostname,"-port",str(options.port),"-tout","2"], stdout=PIPE)
 output = p.communicate()[0]
 if re.search(r’db_total_count’, output ):
   m = re.search(r’db_total_count: ([0-9]*)’, output )
   count = m.group(1)
   m = re.search(r’db_total_size: ([0-9]*)’, output )
   size = m.group(1)
   print “OK: %s %s:%d count:%s size:%s” % (service, options.hostname, options.port, count, size )
 else:
   raise RuntimeError( “%s data invalid” % service )

こんな感じでデータチェックして報告

This entry was posted on 金曜日, 2月 8th, 2013 at 6:30 PM and is filed under Kyototycoon/cabinet, nagios, Python. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。