2018-05-28 Linux Learning

Source: Internet
Author: User

19.12 Adding custom monitoring items

Requirements: Monitor the number of 80-port connections for a web and figure out

Two steps:
1) Zabbix Monitoring Center to create a monitoring project; 2) graphic representation of the monitoring project

For the first step, you need to define the script to the client
vim/usr/local/sbin/estab.sh//content is as follows
#!/bin/bash
# #获取80端口并发连接数
Netstat-ant |grep ': |grep-c established

chmod 755/usr/local/sbin/estab.sh

Edit config file on client vim/etc/zabbix/zabbix_agentd.conf//Add
Unsafeuserparameters=1//means using a custom script
userparameter=my.estab.count[],/usr/local/sbin/estab.sh
The key of the custom monitoring item is My.estab.count, the following [
] script parameters are written, if no parameters can be omitted, the script is/usr/local/sbin/estab.sh
Restart Zabbix-agent Service Systemctl restart Zabbix-agent

First to the server authentication, execute the command
Zabbix_get-s 192.168.106.165-p 10050-k ' My.estab.count '
Then add monitoring items in the Zabbix Monitoring Center (browser) configuration
Key-Value Write My.estab.count
After adding the item, go to "monitoring" and "latest data" to see if the item you just added has data appearing
With the data, you can add graphics.
"Configure"-"hosts"--"graphics"--"Create graphics"

Operation Process

[Email protected] ~]# vim/usr/local/sbin/estab.sh
#!/bin/bash
# #获取80端口并发连接数
Netstat-ant |grep ': |grep-c established

[[email protected] ~]# chmod 755 /usr/local/sbin/estab.sh

[Email protected] ~]# vim/etc/zabbix/zabbix_agentd.conf
Search Unsafeuserparameters Add
Unsafeuserparameters=1
Search Userparameter Add
userparameter=my.estab.count[*],/usr/local/sbin/estab.sh

[[email protected] ~]# systemctl restart zabbix-agent[[email protected] ~]# zabbix_get -s 192.168.106.165 -p 10050 -k ‘my.estab.count‘0

Zabbix Web Settings

配置---主机---aming-02---监控项---创建监控项---名称:并发连接数---键值:my.estab.count添加图形---创建图形---名称:并发连接数---监控项 添加---选择 并发连接数---添加报警:触发器---创建触发器---并发连接数---严重性:警告---表达式 添加---监控项 选 并发连接数---功能:最新的T值 > N --- N : 输入200 ---插入---添加监测中---图形---群组 amingtest---主机 aming-02---图形:并发连接数 ---查看数据

19.13-14 Configuring Message Alarms

Use 163 or QQ mailbox to send alert mail
First log in to your 163 mailbox, set the POP3, IMAP, SMTP service to open
Open and record Authorization code
Then set the email alert to the monitoring center.
"Manage", "Alarm media type", "Create Media type"
{ALERT. SENDTO}, {ALERT. Subject},{alert. MESSAGE}

Create an alarm script mail.py
vim/usr/lib/zabbix/alertscripts/mail.py//Content Reference Https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master /d22z/mail.py
chmod 755/usr/lib/zabbix/alertscripts/mail.py
Create a user that accepts alerts, "manage", "user", "Create User", "Alarm vector", type select "Baojing", note the user's permissions, if there is no need to set permissions to the user group
Set the action, "config", "action", "Create action", name write "SendMail" (Custom), "action" page, the content is as follows
Host:{host.name} {HOST. IP}
Time:{event. DATE} {EVENT. TIME}
Level:{trigger. SEVERITY}
Name:{trigger.name}
Messages:{item.name}:{item. VALUE}
Id:{event.id}
"New Trigger condition", a maintenance state not in maintenance, B trigger warning degree >= not classified

"Action", select the sending user as the user just created, send only to select "Baojing"
Switch to "restore operation" and change the information to the following
Host:{host.name} {HOST. IP}
Time:{event. DATE} {EVENT. TIME}
Level:{trigger. SEVERITY}
Name:{trigger.name}
Messages:{item.name}:{item. VALUE}
Id:{event.id}
Click "New", "Action", select the sending user for the user just created, send only to select "Baojing"
Test alarms

Operation Process

Manage---Alarm media type---Create a media type---name baojing---type script---script name mail.py---script parameter add three {ALERT. SENDTO} {ALERT. SUBJECT} {ALERT. MESSAGE}---added

[Email protected] ~]# vim/usr/lib/zabbix/alertscripts/mail.py
#!/usr/bin/env python
#--Coding:utf-8--
Import Os,sys
Reload (SYS)
Sys.setdefaultencoding (' UTF8 ')
Import getopt
Import Smtplib
From email. Mimetext Import Mimetext
From email. Mimemultipart Import Mimemultipart
From subprocess Import *
def sendqqmail (username,password,mailfrom,mailto,subject,content):
Gserver = ' smtp.163.com '
Gport = 25
Try
msg = Mimetext (Unicode (content). Encode (' Utf-8 '))
Msg[' from '] = Mailfrom
Msg[' to '] = mailto
msg[' reply-to '] = Mailfrom
msg[' Subject '] = Subject
SMTP = Smtplib. SMTP (Gserver, Gport)
Smtp.set_debuglevel (0)
Smtp.ehlo ()
Smtp.login (Username,password)
Smtp.sendmail (Mailfrom, mailto, msg.as_string ())
Smtp.close ()
Except Exception,err:
Print "Send Mail failed. Error:%s "% err
def main (): Br/>to=sys.argv[1]
SUBJECT=SYS.ARGV[2]
CONTENT=SYS.ARGV[3]
# #定义QQ邮箱的账号和密码, you need to change your own account and password (please do not put the real user name and password on the Internet, otherwise you will die badly)
Sendqqmail ('[email protected]', ' aaaaaaaaaa ', '[email protected]', to,subject,content)
Name== "Main":
Main ()

# # # # #脚本使用说明 ######
#1. First, define the email account and password in the script.
#2. Script execution commands are: Python mail.py target Mailbox "message subject" "Message content"

[[email protected] ~]# chmod 755 /usr/lib/zabbix/alertscripts/mail.py测试可以收到邮件[[email protected][email protected] "xxxxxxxx" "121212121212121212"

Zabbix Web Configuration

[email protected] ---添加 --- 权限 所有组 读写(权限错误,无法发送邮件)---更新配置---动作---创建动作---名称 发邮件---新的触发条件 维护状态+非在+维护 触发器示警度+>=+未分类 ---计算方式 A and B ---操作---默认信息 清空再添加以下内容HOST:{HOST.NAME} {HOST.IP}TIME:{EVENT.DATE}  {EVENT.TIME} LEVEL:{TRIGGER.SEVERITY} NAME:{TRIGGER.NAME}messages:{ITEM.NAME}:{ITEM.VALUE}ID:{EVENT.ID}操作---新的---发送到用户---添加---选mike---仅送到 baojing---操作的条件---添加 事件已确认=非确认 ---添加 ---添加恢复操作---默认信息 清空再添加以下内容HOST:{HOST.NAME} {HOST.IP}TIME:{EVENT.DATE}  {EVENT.TIME} LEVEL:{TRIGGER.SEVERITY} NAME:{TRIGGER.NAME}messages:{ITEM.NAME}:{ITEM.VALUE}ID:{EVENT.ID}操作---新的---发送到用户---添加---选mike---仅送到 baojing ---添加 ---添加

19.15 Test Alarms

配置---主机---aming-02 触发器---创建触发器---名称 系统负载---严重性 警告---表达式 添加---监控项---选 Processor load (1 min average per core) ---功能 最新的T值 <1 ---插入---添加监测中---仪表板---问题位置---有问题提示:动作显示完成

2018-05-28 Linux Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.