16-mwancustombak 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. # to enable this script uncomment the case loop at the bottom
  3. # to report mwan status on interface hotplug ifup/ifdown events modify the lines in the send_alert function
  4. send_alert()
  5. {
  6. # variable "$1" stores the MWAN status information
  7. # insert your code here to send the contents of "$1"
  8. echo "$1"
  9. }
  10. gather_event_info()
  11. {
  12. # create event information message
  13. local EVENT_INFO="Interface [ "$INTERFACE" ($DEVICE) ] on router [ "$(uci -p /var/state get system.@system[0].hostname)" ] has triggered a hotplug [ "$ACTION" ] event on "$(date +"%a %b %d %Y %T %Z")""
  14. # get current interface, policy and rule status
  15. local CURRENT_STATUS="$(/usr/sbin/mwan3 status)"
  16. # get last 50 MWAN systemlog messages
  17. local MWAN_LOG="$(echo -e "Last 50 MWAN systemlog entries. Newest entries sorted at the top:\n$(logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x')")"
  18. # pass event info to send_alert function
  19. send_alert "$(echo -e "$EVENT_INFO\n\n$CURRENT_STATUS\n\n$MWAN_LOG")"
  20. }
  21. #case "$ACTION" in
  22. # ifup)
  23. # gather_event_info
  24. # ;;
  25. #
  26. # ifdown)
  27. # gather_event_info
  28. # ;;
  29. #esac
  30. exit 0