/usr/local/zabbix/bin/mysql_session.sh
#!/bin/bash
#this script is used to sort MySQL malicious action
#mysql session
Metric=$1
Case $metric in
Mini
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[$NF]}end{for (A in S) print A,s[a]} ' |awk '/mini/{print '} ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Login
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[$NF]}end{for (A in S) print A,s[a]} ' |awk '/login/{print '} ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Register
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[$NF]}end{for (A in S) print A,s[a]} ' |awk '/register/{print '} ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Ajax_showcart)
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[$NF]}end{for (A in S) print A,s[a]} ' |awk '/ajax_showcart/{print '} ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Init
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[
$NF]}end{for (A in S) print A,s[a]} ' |awk '/init/{print $ ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
PUBLIC_FIND_PWD)
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[$NF]}end{for (A in S) print A,s[a]} ' |awk '/public_find_pwd/{print '} ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Public_session_life)
output=$ (mysql-uroot-pxxxxxx-e "select * from Huiyewang.snto_session;" | Awk-f "|" ' {print $} ' |awk ' {print $9} ' |awk ' {++s[$NF]}end{for (A in S) print A,s[a]} ' |awk '/public_session_life/{print '} ')
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
*)
Echo-e "\e[033musage:sh [mini|login|register|ajax_showcart|init|public_find_pwd|public_session_life]\e[0m"
Esac
Zabbix Agent configuration section
Userparameter=mysql.session[*],/usr/local/zabbix/bin/mysql_session.sh $
This article is from the "Xiangjiang River Blowing Crazy" blog, please make sure to keep this source http://xjcf00.blog.51cto.com/10170403/1642117
Zabbix Statistics MySQL Session table statistics user Internet behavior