Phase 3 Basics
Time: July 20, 2023
Participants: the whole class
Contents:
Zabbix monitoring mailbox alarm
Table of contents
1. Computer login Netease mailbox configuration (save the authorization code!)
2. Install and configure the mail server on the server side (huyang1):
3. Edit zabbix_server.conf to quote the mail script:
4. Configure zabbix web monitoring item email alarm:
Overall server settings:
CPU name | IP address | system | Function | installed services |
weak1 | 192.168.59.137 | linux | server agent |
mysql, mail.sh script mailbox alarm |
weak3 | 192.168.59.140 | linux | agent | ftp,memory_used、du |
Zabbix email alarm
1. Computer login Netease mailbox configuration (save the authorization code!)
2. Install and configure the mail server on the server side (huyang1):
1. Install mail service
yum install -y mailx dos2unix
mailx -V
2. Modify the configuration file
vim /etc/mail.rc
The configuration is as follows: (the last three lines)
Remarks: //Add at the end of this file, specify the receiving email address, specify the email server address, and specify the authorization code of the receiving email address. It is not the password of the 163 mailbox, but the authorization code. After logging in to the 163 Netease email address, --Settings--Enable smtp and pop3--click the client to generate the authorization code--use this authorization code to assign to this configuration file;
3. Send test content
echo "test mail from huyang1"| mail -s"test mail" [email protected] //Send test content
3. Edit zabbix_server.conf to quote the mail script:
vim /usr/local/zabbix/etc/zabbix_server.conf
The configuration is as follows:
cd /usr/local/zabbix/share/zabbix/alertscripts
vim mail.sh
The configuration is as follows:
Remarks: //Write the alarm email script, adjust the syntax position of the mail command, and use the dos2unix command to convert characters, so as to avoid the error of ATT00001.
bt=$2 sjr=$1 defines sender header and recipient information
FILE=/tmp/mailtmp.txt defines the file path
/usr/bin/dos2unix -k $FILE Use the dos2unix command to convert characters, avoiding the ATT00001.bin error due to the received mail not displaying the normal mail content;
/bin/mail -s "$bt" "$sjr" <$FILE execute mail sending command
chmod 777 mail.sh //weight the script
chown zabbix:zabbix mail.sh //Change the group and owner
touch /tmp/mailtmp.txt //Create information file
chmod 777 /tmp/mailtmp.txt //weighting
chown zabbix:zabbix /tmp/mailtmp.txt //Change to the group and owner
Remarks: //Pay attention to the ownership and permissions of files and alarm scripts; the ownership of script files and files storing email messages must be zabbix
./mail.sh [email protected] "test mail2" "test mail from huyang1 test2" //Script test
4. Configure zabbix web monitoring item email alarm:
Monitoring--create alarm media type--update the alarm media type used by the user--create action (triggered according to the trigger)--verify;
Remarks: Enter the name of the created alarm medium type, specify the type as a script, and enter the huyang1 terminal
The name of the script in the /usr/local/zabbix/share/zabbix/alertscripts directory, ensure that the script belongs to zabbix, and the script permission is 777, set the script parameters below, that is, the syntax of sending emails: the title content of the script recipient must be filled in strictly according to this standard;
The three script parameters are as follows:
$1 {ALERT.SENDTO}
$2 {ALERT.SUBJECT}
$3 {ALERT.MESSAGE}
Example: as follows
Confirm the alarm media information :
Configure the alarm media type used by users in zabbix and the mailbox for receiving emails;
Example: as follows
Confirmation information:
Create an action to send email:
Enter the action name, the action name should be in English, and you can choose the condition to trigger this action (you can choose the trigger = the name of the trigger or the name of the trigger like the trigger), as a condition, if you do not choose the condition of the trigger as shown in the figure, then any message will be prompted to the mailbox;
Modify operation:
example:
Modify recovery action:
Modification confirmation operation:
Finally click Add:
Added action templates:
Add an alarm action. Once this trigger is added, add the title and content of the alarm email, the duration of the default operation step (modify the duration to 60 seconds (send an email once a minute)), and add an operation (add a user who receives the email);
The email format is as follows:
Default recipient content: failure {TRIGGER.STATUS}, server: {HOSTNAME1} occurred: {TRIGGER.NAME} failure!
Default message content:
Alarm Host: {HOSTNAME1}
Alarm time: {EVENT.DATE} {EVENT.TIME}
Alarm level: {TRIGGER.SEVERITY}
Alert message: {TRIGGER.NAME}
Alarm item: {TRIGGER.KEY1}
Question Details:{ITEM.NAME}:{ITEM.VALUE}
Current status: {TRIGGER.STATUS}:{ITEM.VALUE1}
Event ID: {EVENT.ID}
5. Test email alarm:
1. Close the ftp service of huyang3
systemctl stop vsftpd.service
There is a failure email
2. Restore the ftp service of huyang3
systemctl start vsftpd
view web graphics
view dashboard
view action log
3. Test the ftp service of huyang1 (huyang1 is both server and agent)
systemctl stop vsftpd.service
Also call the police! ! !
4. Restore the ftp service of huyang1
Status back to normal! ! !
5. Download the Netease mailbox on the mobile phone and log in to the 163 mailbox
verify: