etc_zabbix_zabbix_agentd.d_yunohost.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 --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" --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" --plain 2>/dev/null | awk '/#/{ next;} {printf "%s;",$0} END {print ""}')
  20. if [[ "$service" == *"doesn't exists for systemd"* ]] ;then
  21. echo "$service" | sed 's/\(.*;.*;.*;.*;.*;\).*\(;.*;\)/\1disabled\2/g'
  22. else
  23. echo "$service"
  24. fi
  25. fi
  26. if [ "$1" == "yunohost.backups.number" ] ;then
  27. $yunobin backup list --plain | wc -l
  28. fi
  29. if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then
  30. timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')")
  31. echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) ))
  32. fi
  33. if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then
  34. ports=$($yunobin firewall list -r --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 "]}"
  35. fi
  36. if [ "$1" == "yunohost.ports.udp.discovery" ] ;then
  37. ports=$($yunobin firewall list -r --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 "]}"
  38. fi
  39. if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then
  40. $yunobin tools migrations state | grep -Po " number: \K(.*)"
  41. fi
  42. if [ "$1" == "yunohost.migrations.lastavailable" ] ;then
  43. $yunobin tools migrations list | tail -n 1 | grep -Po " number: \K(.*)"
  44. fi