etc_zabbix_zabbix_agentd.d_yunohost.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. yunobin=$(which yunohost)
  3. if [ "$1" == "yunohost.users.discover" ];then
  4. users=$($yunobin user list --fields 'uid' | awk -F ': ' '/username: / {print $2}');echo -n "{\"data\":[";for user in $users;do echo -n "{\"{#USERNAME}\":\"$user\"},";done | sed 's/,$//' ;echo "]}"
  5. fi
  6. if [ "$1" == "yunohost.user.quota" ] ;then
  7. quota=$($yunobin user info "$2" | grep -Po "use:.*\(\K([0-9]{1,3})");if [ -z "$quota" ];then echo 0 ; else echo "$quota" ;fi
  8. fi
  9. if [ "$1" == "yunohost.domains.discover" ] ;then
  10. domains=$($yunobin domain list --output-as plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}"
  11. fi
  12. if [ "$1" == "yunohost.domain.cert" ] ;then
  13. $yunobin domain cert-status "$2" --output-as plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}'
  14. fi
  15. if [ "$1" == "yunohost.services.discover" ] ;then
  16. services=$($yunobin service status 2>/dev/null| grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}"
  17. fi
  18. if [ "$1" == "yunohost.service.status" ] ;then
  19. service=$($yunobin service status "$2" --output-as json 2>/dev/null)
  20. if [[ "$(echo $service | jq -r '.description')" == *"doesn't exists for systemd"* ]] ;then
  21. echo "$service" | jq -c '.active = "disabled"'
  22. else
  23. echo "$service"
  24. fi
  25. fi
  26. if [ "$1" == "yunohost.backups.number" ] ;then
  27. $yunobin backup list --output-as plain | wc -l
  28. fi
  29. if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then
  30. if [ $($yunobin backup list --output-as plain | wc -l) -ne 0 ] ;then
  31. timestamp=$(date +"%F %R" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')")
  32. echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) ))
  33. else
  34. echo "No backup detected"
  35. fi
  36. fi
  37. if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then
  38. ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}"
  39. fi
  40. if [ "$1" == "yunohost.ports.udp.discovery" ] ;then
  41. ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}"
  42. fi
  43. if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then
  44. $yunobin tools migrations state | grep -Po " number: \K(.*)"
  45. fi
  46. if [ "$1" == "yunohost.migrations.lastavailable" ] ;then
  47. $yunobin tools migrations list | tail -n 1 | grep -Po " number: \K(.*)"
  48. fi