Muninのグラフを定期レポート用にメール送信する方法。
mutt をインストール
複数ファイルを添付する場合はmuttが良さげ。
yum -y install mutt
グラフを添付してメールするbashスクリプト作成
/var/www/cron/munin_graph_send.bash
#!/bin/bash
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# Muninグラフをメール送信するスクリプト Ver.0.1
#
# Author Digichro co. Yoshinori Sakai
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# ─────────────────────────
# ■ 初期設定
# ─────────────────────────
# Muninのグラフ格納ディレクトリ
target_host1_dir=/var/www/html/munin/WEB/target_host1
target_host2_dir=/var/www/html/munin/WEB/target_host2
target_host3_dir=/var/www/html/munin/WEB/target_host3
# レポート用グラフ画像
load_avg=load-month.png
cpu=cpu-month.png
memory=memory-month.png
disk=df-month.png
ipconntrack=fw_forwarded_local-month.png
netstat=netstat-month.png
traffic=if_eth0-month.png
# メール設定
subject='定期レポート用グラフ'
mailbody=`date +%Y年%m月レポート -d '1 days ago'`
mailaddr=myself@example.com
# ─────────────────────────
# ■ メール送信処理
# ─────────────────────────
echo "${mailbody} target_host1" | mutt -s ${subject} ${mailaddr} \
-a ${target_host1_dir}/${load_avg} \
-a ${target_host1_dir}/${cpu} \
-a ${target_host1_dir}/${memory} \
-a ${target_host1_dir}/${disk} \
-a ${target_host1_dir}/${ipconntrack} \
-a ${target_host1_dir}/${netstat} \
-a ${target_host1_dir}/${traffic} ;
echo "${mailbody} target_host2" | mutt -s ${subject} ${mailaddr} \
-a ${target_host2_dir}/${load_avg} \
-a ${target_host2_dir}/${cpu} \
-a ${target_host2_dir}/${memory} \
-a ${target_host2_dir}/${disk} \
-a ${target_host2_dir}/${ipconntrack} \
-a ${target_host2_dir}/${netstat} \
-a ${target_host2_dir}/${traffic} ;
echo "${mailbody} target_host3" | mutt -s ${subject} ${mailaddr} \
-a ${target_host3_dir}/${load_avg} \
-a ${target_host3_dir}/${cpu} \
-a ${target_host3_dir}/${memory} \
-a ${target_host3_dir}/${disk} \
-a ${target_host3_dir}/${ipconntrack} \
-a ${target_host3_dir}/${netstat} \
-a ${target_host3_dir}/${traffic} ;
設置してパーミッションを707にする。
CRONに登録
毎月1日(4:10)にメール送信されるようタスクに登録。
crontab
10 4 1 * * export LANG=ja_JP.UTF-8; /var/www/cron/munin_graph_send.bash #月次レポート
※export LANG=ja_JP.UTF-8 がないとメールのタイトルが文字化けします。