Returns host name to default after device disconnected

Returns host name to default after device disconnected

Introduction:
Often Nodegrid users set the serial port to detect hostname of the connected device to help identify the device in the access page. When the target device is removed the host name remained on the access page.  This page helps the user to automatically change the name back to default name.

Solution:
Scripts are used to run on the disconnect event (307) to replace the hostname back to default for the serial ports.
 
Steps: 
go to the Nodegrid and into "/etc/scripts/auditing" folder create the script Event307.sh as below and makes it an executable script.
The script gets the device name and look for the default serial port name.  If the name is not blank then replace the hostname with the default.

  1. #!/bin/bash

  2. # This script is meant as a sample to event's action script.
  3. # Whenever an event ocurrs, it will execute this script passing the Event
  4. # number as the first argument plus all the arguments that this events
  5. # pass to SNMP TRAP. See Nodegrid-TRAP-MIB.mib to see all args for each event.

  6. EVENT_NUMBER="$1" #argument 1 is always the event number
  7. ARGUMENT2="$2" #depends on the event
  8. ARGUMENT3="$3" #depends on the event
  9. ARG_COUNT="$#" #depends on the event

  10. devName="$2"
  11. output=$(su - admin -c "cli show /settings/devices/$devName/access")
  12. serialPort=$(echo "$output" | awk '/local serial port:/{print $4}')
  13. if [ -n $serialPort ]; then

  14. su - admin -c "cli -f -"<<EOF
  15. cd /settings/devices/
  16. rename $devName
  17. set new_name=$serialPort
  18. commit
  19. EOF

  20. fi
  21. exit 0

In the Nodegrid Web UI, go to "Auditing::Events::Event List" click on "307" Event then add the Event307.sh script in the "Action Script".