r1180 + a new class for warning messages
[racktables] / gateways / switchvlans / cisco.connector
CommitLineData
533aefb8
DO
1#!/bin/sh
2
3[ $# = 4 ] || exit 2
4
5ENDPOINT=$1
6COMMAND=$2
7865c525
DO
7FILE1=$3
8FILE2=$4
533aefb8 9
7865c525 10prepare_fetch_commands()
533aefb8
DO
11{
12 [ $# = 1 ] || exit 1
13 local skip=yes cval
14 while read line; do
15 if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
16 skip=no
17 continue
18 fi
19 if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
20 skip=yes
21 continue
22 fi
23 [ "$skip" = "yes" ] && continue
24 # Allow comments.
25 [ -z "${line###*}" ] && continue
26
27 # First endpoint string/regexp match is sufficient for us.
28 cval=`echo $line | cut -s -d' ' -f1`
29 if [ -z "${1##$cval}" ]; then
30 # Don't be too smart at the moment, just be able to handle
31 # the known-good case ;-)
32
33 echo $line | cut -s -d' ' -f6 > $CMDS1
34 echo en >> $CMDS1
35 echo $line | cut -s -d' ' -f7 >> $CMDS1
36
37 # same for ports
38 echo $line | cut -s -d' ' -f6 > $CMDS2
39 echo en >> $CMDS2
40 echo $line | cut -s -d' ' -f7 >> $CMDS2
41 break
42 fi
43 done < `dirname $0`/cisco.secrets.php
44 printf 'term len 0\nshow vlan brief\nquit\n' >> $CMDS1
45 printf 'term len 0\nshow int status\nquit\n' >> $CMDS2
46}
47
7865c525 48prepare_push_commands()
533aefb8 49{
7865c525
DO
50}
51
52do_fetch()
53{
54 nc $ENDPOINT 23 < $CMDS1 | fgrep active | cut -d' ' -f1 > $FILE1
55 nc $ENDPOINT 23 < $CMDS2 | egrep '^(Et|Fa|Gi|Te)' | sed -E 's/ +(notconnect|connected) +/=/;s/=(trunk|([0-9]+)) .*$/=\1/' > $FILE2
56}
57
58do_push()
59{
60 echo "E!this is a stub" >> "$FILE2"
61 echo "W!this is another stub" >> "$FILE2"
62 echo "I!have a good time!" >> "$FILE2"
533aefb8
DO
63}
64
65# This one is for VLAN list.
66CMDS1=`mktemp /tmp/cisco.connector.XXXX`
67[ -f "$CMDS1" ] || exit 2
68
69# And this one holds ports list.
70CMDS2=`mktemp /tmp/cisco.connector.XXXX`
71if ! [ -f "$CMDS2" ]; then
72 rm -f "$CMDS1"
73 exit 2
74fi
75
76case $COMMAND in
7865c525
DO
77 fetch)
78 prepare_fetch_commands $ENDPOINT
79 do_fetch
533aefb8 80 ;;
7865c525
DO
81 push)
82 prepare_push_commands $ENDPOINT
83 do_push
533aefb8
DO
84 ;;
85 *)
86 rm -f "$CMDS1" "$CMDS2"
87 exit 2
88 ;;
89esac
90
91rm -f "$CMDS1" "$CMDS2"
92exit 0