Browse Source

feat: add scripts

master
yaokl 2 years ago
parent
commit
316ddc717e
  1. 53
      powershell/checkfile-email.ps1
  2. 29
      powershell/checkfile-wechat.ps1
  3. 13
      python/supervisor_healthCheck.py
  4. 22
      python/supervisor_healthCheck.sh
  5. 2
      shell/test/os_repo_speed_test.sh

53
powershell/checkfile-email.ps1

@ -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 +
"
test10.8.8.1
"
$counter= $counter + 1
}
$Emailbody= $Emailbody +
"
告警来源 127.0.0.1
"
if ($counter -gt 0)
{
sendmail
}

29
powershell/checkfile-wechat.ps1

@ -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 +
"
test10.8.8.1
"
$counter= $counter + 1
}
if ($counter -eq 0){
$msg= "Windows Server 备份检查完成,备份状态正常!"
}
$msg= $msg +
"
告警来源 127.0.0.1
"
wechattalk

13
python/supervisor_healthCheck.py

@ -524,7 +524,7 @@ class HealthCheck(object):
restart_result = self.action_supervisor_restart(program) restart_result = self.action_supervisor_restart(program)
msg += '\r\n**Restart**:%s' % restart_result msg += '\r\n**Restart**:%s' % restart_result
elif 'exec' in action_list: elif 'exec' in action_list:
action_exec_cmd = config.get('action_exec_cmd') action_exec_cmd = config.get('execCmd')
exec_result = self.action_exec(program, action_exec_cmd) exec_result = self.action_exec(program, action_exec_cmd)
msg += '\r\n**Exec**:%s' % exec_result msg += '\r\n**Exec**:%s' % exec_result
elif 'kill' in action_list: elif 'kill' in action_list:
@ -712,11 +712,13 @@ class HealthCheck(object):
touser = self.wechat_config.get('touser') touser = self.wechat_config.get('touser')
toparty = self.wechat_config.get('toparty') toparty = self.wechat_config.get('toparty')
totag = self.wechat_config.get('totag') totag = self.wechat_config.get('totag')
webhook = self.wechat_config.get('webhook')
headers = { headers = {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
if corpid and secret and agentid:
access_token_url = '/cgi-bin/gettoken?corpid={id}&corpsecret={crt}'.format(id=corpid, crt=secret) access_token_url = '/cgi-bin/gettoken?corpid={id}&corpsecret={crt}'.format(id=corpid, crt=secret)
try: try:
@ -733,6 +735,9 @@ class HealthCheck(object):
send_url = '/cgi-bin/message/send?access_token={token}'.format(token=token) send_url = '/cgi-bin/message/send?access_token={token}'.format(token=token)
if webhook:
send_url = webhook.replace('https://qyapi.weixin.qq.com','')
ip = "" ip = ""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try: try:
@ -766,11 +771,11 @@ class HealthCheck(object):
data = { data = {
"msgtype": 'markdown', "msgtype": 'markdown',
"agentid": agentid, "markdown": {'content': content}
"markdown": {'content': content},
"safe": 0
} }
if agentid:
data['agentid'] = agentid
if touser: if touser:
data['touser'] = touser data['touser'] = touser
if toparty: if toparty:

22
python/supervisor_healthCheck.sh

@ -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

2
shell/test/os_repo_speed_test.sh

@ -28,7 +28,7 @@ mirrors=(
[edu_tsinghua]="https://mirrors.tuna.tsinghua.edu.cn/" [edu_tsinghua]="https://mirrors.tuna.tsinghua.edu.cn/"
[sohu]="http://mirrors.sohu.com/" [sohu]="http://mirrors.sohu.com/"
[huawei]="https://mirrors.huaweicloud.com/" [huawei]="https://mirrors.huaweicloud.com/"
[netease]="http://mirrors.cn99.com/" [netease]="https://mirrors.163.com/"
[tencent]="https://mirrors.cloud.tencent.com/" [tencent]="https://mirrors.cloud.tencent.com/"
[aliyun]="https://mirrors.aliyun.com/" [aliyun]="https://mirrors.aliyun.com/"
) )

Loading…
Cancel
Save