內部網路使用postfix發送/管理信件

參考資料:
http://blog.miniasp.com/post/2008/03/24/How-to-delete-undelivered-email-in-Postfix.aspx

 

新增/etc/postfix/transport-private-cloud檔案加入下面內容

*               smtp:10.160.1.1

 

執行下列指令

cd /etc/postfix
postmap hash:/etc/postfix/transport-private-cloud

 

修改/etc/postfix/main.cf增加下面設定

#透過command line發信時會帶test.chtos.info網域如root@test.chtos.info
#許多郵件主機會有防SPAM機制,若發信網域不存在mail會直接被reject
mydomain = test.chtos.info
myorigin = $mydomain

#設定mail relay
transport_maps = hash:/etc/postfix/transport-private-cloud

重新啟動postfix

service postfix restart

 

測試command line或是nagios發信

刪除mail queue (轉發自http://blog.miniasp.com/post/2008/03/24/How-to-delete-undelivered-email-in-Postfix.aspx)

# 刪除所有在 Queue 中的郵件
postsuper -d ALL

# 刪除所有正在 deferred 佇列中的郵件 ( 刪除曾經發送失敗的信 )
postsuper -d ALL deferred

# 刪除所有正在 deferred 佇列中的郵件 ( 可看出哪些信被刪除了 )
find /var/spool/postfix/deferred -type f -exec rm -vf \{\} \;

# 刪掉「三天以前」無法發出的郵件
find /var/spool/postfix/deferred -type f -mtime +3 -exec rm -f \{\} \;

# 列出目前所有無法發出的郵件
find /var/spool/postfix/deferred -type f -exec ls -l --time-style=+%Y-%m-%d_%H:%M:%S {} \;

# 刪除超過 5 天的 "defer" 佇列中的退信紀錄
find /var/spool/postfix/defer -type f -mtime +5 -exec rm -f \{\} \;

 

 

PowerCLI – 查詢/設定/重新啟動VMware Host NTP服務

參考資料
Setting ESXi DNS and NTP using PowerCLI

ESX(i) NTP Server settings: PowerCLI

$esxHosts = get-VMHost

foreach ($esx in $esxHosts) {
   Write-Host "Configuring NTP Client Policy on $esx" -ForegroundColor Green
   Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false

   Write-Host "Restarting NTP Client on $esx" -ForegroundColor Green
   Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false

}

 

$vmhosts = Get-VMHost
$details = @()
foreach ($vmhost in $vmhosts) {
    $detail = "" | select Name,NTPServer
    $detail.Name = $vmhost.Name
    $detail.NTPServer = Get-VMHostNtpServer $vmhost
    $details += $detail
}

$details

 

bash script – 透過SNMP檢查VMWare Host NTP同步狀態

#!/bin/bash

for i in 18 19 21 22 23 24 25 26 27 28 29 30 31 32
do
  echo -n "  UCS:`printf %03d $i` "
  snmpwalk -c public -v 2c -Ov 172.24.2.$i hrSystemDate.0
done

for j in 2 3 4 5 6 7 8 18 19 20 21 22 23 24 34 35 36 37 38 39 40 50 51 52 53
do
  echo -n "Blade:`printf %03d $j` "
  snmpwalk -c public -v 2c -Ov 172.24.18.$j hrSystemDate.0
done

for k in {9..15} {25..31} {41..48} 54 {55..56}
do
  echo -n "Blade:`printf %03d $k` "
  snmpwalk -c public -v 2c -Ov 172.24.18.$k hrSystemDate.0
done

 

cacti thold plugin微調

預設Cacti thold plugin在發送告警email時rrd圖檔顯示的內容為1day週期,因特殊需求需調整成2hrs,需修改/usr/share/cacti/plugins/thold/thold_functions.php

2811,2815c2811
<                       #$graph_data_array = array('output_flag'=> RRDTOOL_OUTPUT_STDOUT);
<                         $graph_end_time = date("U");
<                         $graph_start_time = $graph_end_time - 7200;
<                         $graph_data_array = array('output_flag'=> RRDTOOL_OUTPUT_STDOUT, 'graph_start'=>$graph_start_time, 'graph_end'=>$graph_end_time);
<
---
>                       $graph_data_array = array('output_flag'=> RRDTOOL_OUTPUT_STDOUT);