5.02021-11-21T22:08:35ZTemplates/ModulesModule Linux Active User Status by Zabbix Agent activeModule Linux Active User Status by Zabbix Agent active## Description
This template collects and monitors active users on target hosts.
## Overview
# Zabbix Template for monitoring Active User Status by Zabbix Agent active
This template try to monitor active users on servers and find out overstay users
1. Monitor Items
1. Logged in users List
1. Num of Active(logged in) users
1. Overstay users on the {HOST.NAME} > {$OVERSTAY\_THRESHOLD} day(s)
1. Num of overstay users on the {HOST.NAME} > {$OVERSTAY\_THRESHOLD} day(s)
- Triggers
Some users overstay on the {HOST.NAME} > {$OVERSTAY\_THRESHOLD} day(s)
## Tested version
- Zabbix: `5.0.1`
## Useage
1. Import Templates: Zabbix Web Page --> [Configuration] --> [Templates] --> [Import] this xml file
1. Link this template to an existing host or a new host
1. Update the Macro to specify your Harbor info: [Configuration] --> your host --> [Macros] --> [Inherited and host macros]
- {$OVERSTAY\_THRESHOLD}
## Author
Yioda
Templates/ModulesActive User StatusOS- Logged in usersZABBIX_ACTIVEsystem.run["TZ=UTC last -FRw | grep \"still logged\" | sed 's/still logged in//g' | awk '{$2=\"\";print $0;}' | sed 's/ /,/g'"]1h0TEXTUse linux command `last` to get those users with status "still logged in".Active User StatusOSJAVASCRIPTvar conns = value.split('\n');
var new_conns = [];
for(var i=0; i<conns.length; i++){
if (conns[i].length === 0){
continue;
}
var conn_info = conns[i].split(',');
var user = conn_info[0];
var time = new Date(conn_info[1]);
new_conns.push({user: user, login: time});
}
return JSON.stringify(new_conns);
- Num of Active(logged in) usersDEPENDENTsystem.users.loggedin.num0Same purpose as the Zabbix built-in metric `system.users.num`.Active User StatusOSJAVASCRIPTreturn JSON.parse(value).length;system.run["TZ=UTC last -FRw | grep \"still logged\" | sed 's/still logged in//g' | awk '{$2=\"\";print $0;}' | sed 's/ /,/g'"]
- Overstay users on the {HOST.NAME} > {$OVERSTAY_THRESHOLD} day(s)DEPENDENTsystem.users.overstay.list00TEXTActive User StatusOSJAVASCRIPTvar conns = JSON.parse(value);
var overstay_conns = [];
var threshold = '{$OVERSTAY_THRESHOLD}';
for (var i=0; i<conns.length; i++){
var login_date = new Date(conns[i].login);
var current_date = new Date();
var stay_days = (current_date - login_date)/(1000*60*60*24*threshold);
if (stay_days >= 1) {
overstay_conns.push(conns[i]);
}
}
return JSON.stringify(overstay_conns);system.run["TZ=UTC last -FRw | grep \"still logged\" | sed 's/still logged in//g' | awk '{$2=\"\";print $0;}' | sed 's/ /,/g'"]
- Num of overstay users on the {HOST.NAME} > {$OVERSTAY_THRESHOLD} day(s)DEPENDENTsystem.users.overstay.num0Active User StatusOSJAVASCRIPTreturn JSON.parse(value).length;system.users.overstay.list{last()}>0Some users overstay on the {HOST.NAME} > {$OVERSTAY_THRESHOLD} day(s)WARNING
{$OVERSTAY_THRESHOLD}1stay on certain server too long, default: 1 day