event-action-python-aos-r8
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| event-action-python-aos-r8 [2020/09/09 12:53] – [Ein einfaches Beispiel als Codegerüst: chassis_trap.py] benny | event-action-python-aos-r8 [2024/06/09 10:29] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 308: | Zeile 308: | ||
| ===== Fortgeschritten ===== | ===== Fortgeschritten ===== | ||
| - | ==== OmniSwitch-Konfiguration via scp exportieren ==== | + | ==== Anwendungsfall: |
| - | - key-pair erzeugen | + | Damit der OmniSwitch nach erfolgreichem "write memory flash-synchro" |
| - | - known_hosts | + | |
| - | - identity_file mit zugriffsrechten | + | |
| + | - Ein SSH private/ | ||
| + | - Bei einer Automatisierung ist eine " | ||
| + | - Damit die Verbindung per SSH/SCP erfolgreich ist, muss das identity_file mit korrekten Zugriffsrechten hinterlegt werden | ||
| + | - Das Skript auf dem Switch hinterlegen | ||
| + | - Mit " | ||
| + | - Den Vorgang testen | ||
| + | === 1. SSH private/ | ||
| + | < | ||
| + | ssh-keygen -t rsa -b 2048 -C " | ||
| + | </ | ||
| + | Der resultierende id_rsa.pub-Key muss für den Benutzer in ~/ | ||
| + | |||
| + | === 2. Automatisierung von SSH-Host-Fingerprint yes/no === | ||
| + | |||
| + | Der Zusatz **-o StrictHostKeyChecking=no** sollte nur verwendet werden, wenn man mit der Konsequenz einer potentiellen MITM-Attacke leben kann. Bitte beachten dass das Skript fehlschlagen wird, wenn sich der SSH-Host-Fingerprint ändert. Das könnte man zwar auch wegkonfigurieren, | ||
| + | |||
| + | < | ||
| + | Switch-> scp -i / | ||
| + | </ | ||
| + | |||
| + | === 3. Korrekte Zugriffsrechte für ssh_private_key === | ||
| + | |||
| + | < | ||
| + | Switch-> chmod 600 / | ||
| + | </ | ||
| + | |||
| + | === 4. Skript für Export === | ||
| + | Vorausgesetzt die Tipps aus diesem Artikel wurden angewendet, kann nun mit diesem Skript die Konfiguration extern abgelegt werden. Das folgende Skript hier abspeichern: | ||
| + | |||
| + | <file python chassis_trap.py> | ||
| + | # | ||
| + | |||
| + | import sys | ||
| + | import os | ||
| + | import getopt | ||
| + | import json | ||
| + | import subprocess | ||
| + | |||
| + | # Based upon work done by Patricio Martelo and Benny Eggerstedt in 2015 | ||
| + | # Some corrections and enhancements done by Benny in 2020 | ||
| + | |||
| + | # Variables to set by customer | ||
| + | ssh_priv_key = "/ | ||
| + | config_to_backup = "/ | ||
| + | scp_target_user = " | ||
| + | scp_host = " | ||
| + | scp_path = "/ | ||
| + | |||
| + | # Get system name | ||
| + | system_name = os.uname()[1].replace(" | ||
| + | |||
| + | # Uncomment during early stage of development | ||
| + | # | ||
| + | |||
| + | # 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: | ||
| + | except getopt.GetoptError as err: | ||
| + | print(err) | ||
| + | print(" | ||
| + | sys.exit(2) | ||
| + | traptype = " | ||
| + | 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 == " | ||
| + | traptype = a | ||
| + | elif o == " | ||
| + | trapdata = a | ||
| + | |||
| + | # | ||
| + | # | ||
| + | |||
| + | # | ||
| + | |||
| + | trapdetail = json.loads(trapdata) | ||
| + | |||
| + | # | ||
| + | |||
| + | if trapdetail[" | ||
| + | # This type of trap is sent when write memory flash-synchro finished | ||
| + | # | ||
| + | # When the "write memory flash-synchro" | ||
| + | if " | ||
| + | system_date = subprocess.check_output([" | ||
| + | system_time = subprocess.check_output([" | ||
| + | timestamp = system_date + " | ||
| + | os.system(" | ||
| + | print(" | ||
| + | </ | ||
| + | |||
| + | **5. Mit " | ||
| + | < | ||
| + | Switch-> event-action trap chassisTrapsAlert script / | ||
| + | </ | ||
| + | |||
| + | **6. Testen:** | ||
| + | < | ||
| + | Switch-> write memory flash-synchro | ||
| + | </ | ||
| + | |||
| + | **Ausgabe auf der Switch-Konsole: | ||
| + | < | ||
| + | {' | ||
| + | |||
| + | Wed Sep 9 18:16:07 : ChassisSupervisor MipMgr INFO message: | ||
| + | +++ Copy running to certified succeeded | ||
| + | {' | ||
| + | Please wait... | ||
| + | Executing: program / | ||
| + | Sending file modes: C0644 4312 vcboot.cfg | ||
| + | Sink: C0644 4312 vcboot.cfg | ||
| + | Process finished! | ||
| + | </ | ||
| ===== Fehleranalyse ===== | ===== Fehleranalyse ===== | ||
| Zeile 335: | Zeile 452: | ||
| Der Zusatz -o StrictHostKeyChecking=no führt dazu dass man die Identität des Servers nicht bestätigen muss. Die Identität des Servers wird aber trotzdem in ~/ | Der Zusatz -o StrictHostKeyChecking=no führt dazu dass man die Identität des Servers nicht bestätigen muss. Die Identität des Servers wird aber trotzdem in ~/ | ||
| < | < | ||
| - | scp -i /flash/python/ | + | scp -i /path/to/ |
| </ | </ | ||
event-action-python-aos-r8.1599655986.txt.gz · Zuletzt geändert: (Externe Bearbeitung)
