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.
- #!/bin/bash
- # This script is meant as a sample to event's action script.
- # Whenever an event ocurrs, it will execute this script passing the Event
- # number as the first argument plus all the arguments that this events
- # pass to SNMP TRAP. See Nodegrid-TRAP-MIB.mib to see all args for each event.
- EVENT_NUMBER="$1" #argument 1 is always the event number
- ARGUMENT2="$2" #depends on the event
- ARGUMENT3="$3" #depends on the event
- ARG_COUNT="$#" #depends on the event
- devName="$2"
- output=$(su - admin -c "cli show /settings/devices/$devName/access")
- serialPort=$(echo "$output" | awk '/local serial port:/{print $4}')
- if [ -n $serialPort ]; then
- su - admin -c "cli -f -"<<EOF
- cd /settings/devices/
- rename $devName
- set new_name=$serialPort
- commit
- EOF
- fi
- 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".