#!/bin/python3 import sys import os import getopt import json # Based on work by Patricio Martelo # Adaption for Link-Aggregation management by Benny # TODO: Delete, just for tests #print(sys.argv) # Load the data that is being sent to us # -t holds the traptype # -d holds the trapdata try: opts, args = getopt.getopt(sys.argv[1:], "t:d:") except getopt.GetoptError as err: print(error) print("%s" % sys.argv) sys.exit(2) traptype = "(none)" trapdata = "{}" # Go through the data in opts and allocate it properly # traptype gets the value from -t # trapdata gets the value from -d for o, a in opts: if o == "-t": traptype = a elif o == "-d": trapdata = a # Load the data from json format into Python dictionary trapdata = json.loads(trapdata); if traptype == 'lnkaggAggDown': if trapdata['traplnkaggPortIfIndex'] == 1001: print('Detected 10G port leaving the aggregate, bringing up backup 1G.\n') os.system("interfaces 1/1/1b admin-state enable") elif traptype == 'lnkaggAggUp': if trapdata['traplnkaggPortIfIndex'] == 1002: print('Restored the operation, running on 1G backup.\n') elif traptype == 'lnkaggPortLeave': if trapdata['traplnkaggPortIfIndex'] == 1001: print('Detected 10G port leaving the aggregate, bringing up backup 1G.\n') os.system("interfaces 1/1/1b admin-state enable") elif traptype == 'lnkaggPortJoin': if trapdata['traplnkaggPortIfIndex'] == 1001: print('Detected 10G port joining the aggregate, bringing down backup 1G.\n') os.system("interfaces 1/1/1b admin-state disable")