赞
踩
| 字段名称 | 字段类型 | 解释 |
| Id | int | 自增ID |
| Table | string | 监测表名 |
| Metric | string | 监测指标 |
| Template | string | 告警模版 |
| Frequency | string | 告警频率 |
| Threshold | string | 指标阈值 |
| CreatedAt | timestamp | 创建时间 |
| UpdatedAt | timestamp | 修改时间 |
## 打开定时任务配置文件
crontab -e
## 指定每个工作日上午11:10定时执行脚本,并把执行脚本的日志写入文件 result.log
10 11 * * 1,2,3,4,5 sh [alert.sh](http://alert.sh) > result.log
const openUrl = "https://oapi.dingtalk.com/robot/send?access_token=43e4ad2bcbbef692c7652b9eecca6fd51a0db9e544edcb579640e78f71259006" // NotifyHandler NotifyHandler type NotifyHandler struct { web.BaseHandler } // POST method func (NotifyHandler) POST(ctx *web.Context) { //1.根据POST表单拼接SQL var rules []model.AlertRule rules, err := model.GetRules() if err != nil { ctx.JSON("Describe AlertRule", 101, err) return } //2. 查询记录匹配告警模版 for _, rule := range rules { switch rule.Table { case "es_logicaldisk": threshold, err := strconv.Atoi(rule.Threshold) if err != nil { ctx.JSON("Describe AlertRule Threshold ,table es_logicaldisk", 101, err) return } disks, err := model.GetDiskInfo(threshold) if err != nil { ctx.JSON("Describe GetDiskInfo Fail", 101, err) return } if len(disks) != 0 { for _, disk := range disks { alarmStr := fmt.Sprintf("时间: %s\n告警标题:逻辑磁盘容量超出%v\n业务IP:%v\n序列号:%v\n磁盘:%v使用百分比%v", time.Now().Format("2006-01-02 15:04:05"), rule.Threshold, disk.BusinessIp, disk.SN, disk.Filesystem, disk.UsePercent) err := notify.SendDingCh(openUrl, alarmStr) if err != nil { ctx.JSON("Describe LogicalDisk", 101, err) return } } } case "es_logininfo": logins, err := model.GetLoginInfo() if err != nil { ctx.JSON("Describe GetLoginInfo Fail", 101, err) return } if len(logins) != 0 { for _, login := range logins { alarmStr := fmt.Sprintf("时间: %s\n告警标题:超过30天未登录\n业务IP:%v\n序列号:%v\n上次登录时间:%v\n,距今间隔:%v", time.Now().Format("2006-01-02 15:04:05"), login.BusinessIp, login.SN, login.StartTime, login.Interval) err := notify.SendDingCh(openUrl, alarmStr) if err != nil { ctx.JSON("Describe LoginInfo", 101, err) return } } } } } ctx.JSON(fmt.Sprintf("ALL Alert Info Already send"), 0, nil) }




## 安装Ansible yum install -y ansible yum install -y sshpass ### 修改配置,忽略告警 vim /etc/ansible/ansible.cfg [defaults] host_key_checking = False # 第一次远程ssh主机需要将机器指纹添加到known_hosts,此设置忽略该步骤 command_warnings=False #忽略ansible执行命令的告警信息 deprecation_warnings=False ### 增加test用户组 vim /etc/ansible/hosts [test] 127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=xxx ### 执行命令,验证功能 ansible test -m shell -a 'lspci' ## 批量机器登录 + 执行shell命令 1. ip列表写入ip_list.ini 2. 执行脚本 sh auto_ssh.sh $Password
#!/bin/bash if [ -s ./result.ini ] ; then > result.ini fi Password=$1 sed -i '/ansible_ssh/d' /etc/ansible/hosts # 添加机器信息 for Ip in $(cat ip_list.ini) do Username="root" echo -e "$Ip ansible_ssh_user=$Username ansible_ssh_port=22 ansible_ssh_pass=$Password" >> /etc/ansible/hosts done # [test]用户组 执行命令 ansible test -m shell -a 'lspci' > result.ini echo "All Hosts Ansible Done , please check result.ini ! ! !"
## 安装expect yum install -y expect ## 单台机器登录 sh login.sh $Ip $Pwd ## 单台机器登录 + 执行shell命令 1. 执行命令写入execute_cmd.ini 2. 执行脚本 sh cmd_login.sh $Ip $Pwd ## 批量机器登录 + 执行shell命令 1. ip列表加入ip_list.ini 2. 执行命令写入execute_cmd.ini 3. 执行脚本 sh list_cmd_login.sh $Pwd
#!/usr/bin/expect
set user "root"
set host [lindex $argv 0]
set port "22"
set password [lindex $argv 1]
spawn ssh -p$port $user@$host
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*assword:" { send "${password}\r" }
}
interact

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。