Zabbix monitoring logging of recent Linux server logins

Source: Internet
Author: User

Monitor the number of login information for the server in half a year with Zabbix custom items. Before you start the configuration, you need to write a script to get the server's logon situation, with the following script:

[[email protected] 09:14 am ~ 1119]# cat logon_count.sh #!/bin/bash#  author: hm  email: [email protected]# system login countoption=$ 1count1=0count3=0count6=0total0=$ (last | grep -ev  "reboot|^$|wtmp"  | wc -l) login_file=/tmp/.loginwho /var/log/wtmp > ${login_file} && chown  Zabbix. ${login_file}d1= ' date -d "1 month ago"  + "%s" ' d3= ' date -d "3 month  ago " +"%s "' d6= ' date -d" 6 month ago " +"%s "' ifs=$ ' \ n ' for i in  ' cat   $login _file ' do    riqi= ' echo  $i  | awk  ' { print $3 '   "$4"   "$5 } '  | xargs -i  date -d " {} " " +%s "'      if [  "$riqi"  -gt  "$d 1"  ];then         count1=$[  $count1 + 1 ]    fi    if [  "$riqi"  -gt   "$d 3"  ];then        count3=$[  $count 3 + 1  ]    fi    if [  "$riqi"  -gt  "$d 6"  ]; then        count6=$[  $count 6 + 1 ]     fidonecase  $option  in    d1)          echo ${count1} ;;     D3)         echo ${count3} ;;     D6)         echo ${count6} ;;     D0)         echo ${total0} ;;     *)         echo -e  "Usage: sh  $0 [d1|D3|D6|D0] "Esac 

Run the script

[Email protected] 09:15 am ~ 1120]#/logon_count.sh d1 #1个月内的登录次数54 [[email protected] 09:16 AM ~ 1121]#./logon_count . SH d3 #3个月内的登录次数240 [[email protected] 09:16 AM ~ 1122]#./logon_count.sh d6 #6个月内的登录次数390 [[email protected] 09:16 A M ~ 1123]#./logon_count.sh D0 #所有的登录次数469

First, configure items

1. Configuration->items->create Item

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/8E/1D/wKiom1i2K1LQHgZLAACcqX9XnIU360.png "title=" 1.png "alt=" Wkiom1i2k1lqhgzlaaccqx9xniu360.png "/>


2, create all the item, as follows

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/8E/1D/wKiom1i2I5KDGO0sAABTSrydfW4809.png "title=" 2.png "alt=" Wkiom1i2i5kdgo0saabtsrydfw4809.png "/>


3. Create graphs Graphic Display items

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/8E/1B/wKioL1i2JAfjcl2kAAC_ypIMnjs274.png "title=" 3.png "alt=" Wkiol1i2jafjcl2kaac_ypimnjs274.png "/>


4, the host hosts to add monitoring projects to complete the Zabbix Web-side configuration

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/8E/1B/wKioL1i2JcDgDbVHAADssNTbDtI687.png "title=" 4.png "alt=" Wkiol1i2jcdgdbvhaadssntbdti687.png "/>


Second, the configuration Userparameter

1. Add a line to the Userparameter configuration file

Userparameter=login_count[*],/usr/local/zabbix/scripts/logon_count.sh $

2. Restart Zabbix_zgentd

[Email protected] 09:41 AM ~ 1124]# Service Zabbix_agentd Restart


Third, after the configuration is complete, the effect is as follows

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/8E/1D/wKiom1i2K9-BuqHNAADsyEi1jVU449.png "title=" 5.png "alt=" Wkiom1i2k9-buqhnaadsyei1jvu449.png "/>



This article is from the "7414593" blog, please be sure to keep this source http://7424593.blog.51cto.com/7414593/1902225

Zabbix monitoring logging of recent Linux server logins

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.