#!/bin/bash

agent_modify(){
sudo mkdir /opt/scripts
sudo chown -R ec2-user:ec2-user /opt/scripts
cd /opt/scripts
cat >/opt/scripts/service_status.sh<<EOF
#!/bin/bash
SERVER_NAME=\$1
ps -ef|grep -w \${SERVER_NAME}|grep -Ev "grep|bash"|wc -l
EOF

sudo chown -R ec2-user:ec2-user /etc/zabbix/
cat >/etc/zabbix/zabbix_agentd.d/service_status.conf<<EOF
UserParameter=services.status[*],/opt/scripts/services_status.sh \$1
EOF
}

agent_modify
sudo chmod +x /opt/scripts/*
sudo systemctl restart zabbix-agent.service
