# カテゴリ用のヘッダとボディを上書きでセット
rawbody = ""
try:
+ append_line(logfile,"[%s] message :%s" % (func_name,message,))
try:
- #del headers["Content-Transfer-Encoding"]
- pass
+ del headers["Content-Transfer-Encoding"]
+ message = message.encode('utf-8')
+ message = str(message)
except:
pass
- message = str(message)
+ append_line(logfile,"[%s] lang %s" % (func_name,os.environ['LANG']))
extra_args = {"message":message}
eml = emlParser().read_conf(extra_args=extra_args)
+ parse_ret = preprint_r(eml,return_var=True)
+ append_line(logfile,"[%s] parse_ret :%s" % (func_name,parse_ret,))
+
header = eml['@message']['value']['header']['value']
rawbody += eml['@message']['value']['rawbody']['value']
for _k,_v in header.iteritems():
headers[_k] = _v['value']
except:
pass
+ try:
+ extra_message = extra_message.encode('utf-8')
+ except:
+ pass
rawbody += "\n\n" + extra_message
+ append_line(logfile,"[%s] rawbody :%s" % (func_name,rawbody,))
+ #sys.exit()
mail.set_body(rawbody)
#preprint_r(mail.msg._headers)
for _k,_v in headers.iteritems():
+ append_line(logfile,"[%s] Headers %-12s: %s" % (func_name,_k,_v))
try:
del mail.msg[_k]
except:
else:
mail.msg[_k] = _v
+ try:
+ del mail.msg["Content-Transfer-Encoding"]
+ mail.msg["Content-Transfer-Encoding"] = "base64"
+ except:
+ pass
+
for _header in mail.msg._headers:
append_line(logfile,"[%s] Header %-12s: %s" % (func_name,_header[0],_header[1]))
#sys.exit()
"""
- message = """From:
-To:
-Subject: ほげふが
+ message = """Subject: [Karesansui Notifier] 危険値を越えました。CPU - %{type_instance}
Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
-通知メールのサンプルです。
-CPUプラグイン
-Failure
+レポート時刻: %{current_time}
+
+ホスト %{hostname} の CPU %{type_instance} が危険値を越えました。
+
+危険値は、%{failure_max} に設定されています。
+現在の値は、 %{current_value} です。
"""
########################################################
# messageを展開、ds.xxxxをdata_valueとして取り出す
########################################################
- percentage = None # ThresholdのPercentage用の変数
+ percentage = False
# messageを展開、ds.xxxxをds_xxxとして取り出す
# Filterの時はdict文字列をexec展開して抽出
msg = message
regex = "^Host (?P<host>.+), plugin (?P<plugin>.+) type (?P<type>.+) \(instance (?P<type_instance>.+)\): "
regex += "Data source \"(?P<ds_name>.+)\" is currently (?P<ds_value>.+)\. "
- regex += "That is (below|above) the (failure|warning) threshold of (?P<ts_value>[\-0-9\.]+)\."
+ regex += "That is (below|above) the (failure|warning) threshold of (?P<ts_value>[\-0-9\.]+)(?P<percent_flag>%?)\."
m = re.match(regex,message)
if m:
- ds_name = m.group('ds_name')
- ds_value = m.group('ds_value')
- percentage = m.group('ts_value')
+ ds_name = m.group('ds_name')
+ ds_value = m.group('ds_value')
+ ts_value = m.group('ts_value')
+ if m.group('percent_flag') == "%":
+ percentage = True
# ds_valueが浮動小数点形式の文字列なら数値に変換
try:
except:
pass
append_log("ds_value : %f" % (ds_value,) ,4)
+ try:
+ append_log("ts_value : %f" % (ts_value,) ,4)
+ except:
+ pass
append_log("percentage : %s" % (percentage,) ,4)
append_log("",4)
check_continuation = 60
check_span = 60 * 60 * 6
- watch_data = query_watch_data(plugin,plugin_instance,type,type_instance,ds_name)
+ watch_data = query_watch_data(plugin,plugin_instance,type,type_instance,ds_name,host=host)
append_log("watch_data : %s" % (str(watch_data),) ,4)
watch_column = [ 'name',
# メッセージを作成
if severity == NOTIF_OKAY:
- alert_msg = "The value of %s (%f) is out of range." % (name,ds_value,)
+ alert_msg = "The value of %s (%f) is within normal range again." % (name,ds_value,)
elif severity == NOTIF_WARNING:
alert_msg = "The value of %s (%f) is within the warning region." % (name,ds_value,)
elif severity == NOTIF_FAILURE:
alert_msg = "The value of %s (%f) is within the failure region." % (name,ds_value,)
+
+ # taizo
try:
- threshold_min
- if percentage is None:
- float(threshold_min)
- alert_msg += " (min:%f)" % (threshold_min,)
- else:
- alert_msg += " (min:%s)" % (threshold_min,)
- except:
- pass
- try:
- threshold_max
- if percentage is None:
- float(threshold_max)
- alert_msg += " (max:%f)" % (threshold_max,)
+ ts_value
+ if percentage is True:
+ alert_msg += " (threshold:%f%%)" % (float(ts_value),)
else:
- alert_msg += " (max:%s)" % (threshold_max,)
+ alert_msg += " (threshold:%f)" % (float(ts_value),)
except:
pass
kss_metadata = karesansui.db.get_metadata()
kss_session = karesansui.db.get_session()
+ myhostname = os.uname()[1]
+ if host == myhostname:
+ host = None
+
from karesansui.db.access.watch import \
findbyall as w_findbyall, \
findby1 as w_findby1, \
findbyand as w_findbyand
retval = []
+
plugin_selector = create_plugin_selector(plugin_instance,type,type_instance,ds,host)
#import pdb; pdb.set_trace()
try:
'notify_mail_from',
'notify_mail_to']
- plugin = "memory"
- plugin_instance = ""
- type = "memory"
- type_instance = "used"
+ plugin = "cpu"
+ plugin_instance = "0"
+ type = "cpu"
+ type_instance = "user"
ds = "value"
+ host = None
+ host = "kss7.kss.local.hde.co.jp"
from karesansui.lib.utils import preprint_r
- watch_data = query_watch_data(plugin,plugin_instance,type,type_instance,ds)
+ watch_data = query_watch_data(plugin,plugin_instance,type,type_instance,ds,host=host)
preprint_r(watch_data)
try:
for column_name in watch_column:
self.dop.addconf(self._module,{})
self.base_parser_name = Parser.__name__
+
+ self.encoding = "UTF-8"
pass
def source_file(self):
message = open(file).read()
mail = email.Parser.Parser().parsestr(message)
+
headers = mail._headers
msgs = self._parse_mail(mail)
pass
try:
- extra_args["message"]
- if extra_args["message"] != "" and extra_args["message"] is not None:
- mail = self.parse(message=extra_args["message"])
+ message = extra_args["message"]
+
+ try:
+ message = message.encode(self.encoding)
+ except:
+ pass
+
+ if message != "" and message is not None:
+ mail = self.parse(message=message)
headers = mail['headers']
msgs = mail['msgs']