mirror of https://github.com/lework/script
yaokl
2 years ago
5 changed files with 129 additions and 20 deletions
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
function sendmail() |
||||
{ |
||||
function mailoptions($mailaddr,$body) #定义发送邮件的方法 |
||||
{ |
||||
$msg=New-Object System.Net.Mail.MailMessage |
||||
$msg.To.Add($mailaddr) |
||||
$msg.From = New-Object System.Net.Mail.MailAddress("notice@test.com", "备份点检员",[system.Text.Encoding]::GetEncoding("UTF-8")) #发件人 |
||||
$msg.Subject = "Windows备份失败通知!" |
||||
$msg.SubjectEncoding = [system.Text.Encoding]::GetEncoding("UTF-8") |
||||
$msg.Body =$body |
||||
$msg.BodyEncoding = [system.Text.Encoding]::GetEncoding("UTF-8") |
||||
$msg.IsBodyHtml = $false #发送html格式邮件 |
||||
$client = New-Object System.Net.Mail.SmtpClient("smtp.qiye.163.com") #配置smtp服务器 |
||||
$client.Port = 25 #指定smtp端口 |
||||
$client.UseDefaultCredentials = $false |
||||
$client.Credentials=New-Object System.Net.NetworkCredential("notice@test.com", "xxxxxxxx") |
||||
try {$client.Send($msg)} |
||||
catch [Exception] |
||||
{$($_.Exception.Message) |
||||
$mailaddr |
||||
} |
||||
} |
||||
|
||||
$tomailaddr = "ops@test.com" |
||||
mailoptions $tomailaddr $Emailbody |
||||
} |
||||
|
||||
|
||||
|
||||
$Emailbody= "Dear All : |
||||
" |
||||
|
||||
$counter= 0 |
||||
|
||||
#test备份检查 |
||||
if (Get-ChildItem D:\serverbackup\WindowsImageBackup\test\Catalog | Where{$_.LastWriteTime -lt (Get-Date).AddDays(-32)}) |
||||
{ |
||||
$Emailbody= $Emailbody + |
||||
" |
||||
○ test(10.8.8.1): |
||||
" |
||||
$counter= $counter + 1 |
||||
} |
||||
|
||||
$Emailbody= $Emailbody + |
||||
" |
||||
告警来源 127.0.0.1 |
||||
" |
||||
|
||||
if ($counter -gt 0) |
||||
{ |
||||
sendmail |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
function wechattalk() |
||||
{ |
||||
curl -Method Get "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxx" |
||||
} |
||||
|
||||
$msg= "Windows Server备份失败通知! |
||||
" |
||||
$counter= 0 |
||||
|
||||
#备份检查 |
||||
if (Get-ChildItem D:\serverbackup\WindowsImageBackup\test\Catalog | Where{$_.LastWriteTime -lt (Get-Date).AddDays(-32)}) |
||||
{ |
||||
$msg= $msg + |
||||
" |
||||
○ test(10.8.8.1): |
||||
" |
||||
$counter= $counter + 1 |
||||
} |
||||
|
||||
if ($counter -eq 0){ |
||||
$msg= "Windows Server 备份检查完成,备份状态正常!" |
||||
} |
||||
|
||||
$msg= $msg + |
||||
" |
||||
告警来源 127.0.0.1 |
||||
" |
||||
|
||||
wechattalk |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
mkdir /etc/supervisord.d/scripts |
||||
|
||||
cat <<EOF > /etc/supervisord.d/healthCheck.ini |
||||
[program:healthCheck] |
||||
command=/etc/supervisord.d/scripts/supervisor_healthCheck.py |
||||
process_name=%(program_name)s |
||||
numprocs=1 |
||||
directory=/etc/supervisord.d/scripts/ |
||||
autostart=true |
||||
startsecs=2 |
||||
startretries=5 |
||||
autorestart=true |
||||
stopsignal=TERM |
||||
stopwaitsecs=3 |
||||
stopasgroup=true |
||||
killasgroup=true |
||||
user=root |
||||
redirect_stderr=true |
||||
stdout_logfile=/var/log/supervisor/healthCheck.log |
||||
stdout_logfile_maxbytes=200MB |
||||
stdout_logfile_backups=10 |
||||
EOF |
Loading…
Reference in new issue