Benutzer-Werkzeuge

Webseiten-Werkzeuge


omnivista-restful-api

OmniVista 2500 RESTful API

In den folgenden Beiträgen beschreiben wir wie die RESTful API von OmniVista 2500 v4.2.1 angesprochen werden kann. Die API kann genutzt werden um Vorgänge zu automatisieren die sonst jemand manuell über den Webbrowser durchführen müsste.

OmniVista RESTful API mit cURL ansprechen

Ich empfehle beim Einsatz von „cURL“ auch die Installation und Verwendung von jq, da die längeren json-Ausgaben sonst schnell unübersichtlich werden.

In den Beispielen habe ich die Ausgabe von cURL reduziert. Für den Fall dass man noch etwas entwickelt, macht es mehr Sinn sich mit „-i“ und „-v“ zusätzliche Informationen ausgeben zu lassen.

Kurze Referenz was sich hinter den Optionen von cURL verbirgt (für alles weitere $ man curl):

  • -d = Daten die man übertragen möchte
  • -F = Überträgt die Daten als wenn sie aus einem Formular kommen (<form>) im multipart/form-data Format
  • -H = Header festlegen (kann mehrfach für mehrere Header verwendet werden)
  • -i = HTTP Response Ausgaben anzeigen
  • -k = Unsichere Verbindung ignorieren (https mit self-signed im Labor)
  • -s = Keine Ausgaben außer dem Ergebnis auf der Console ausgeben (übersichtlicher)
  • -v = Mehr Details anzeigen (kann mehrfach verwendet werden -vvv)
  • -X = HTTP Methode (GET, POST, PUT, DELETE)

Anmeldung an der API von OmniVista 2500 v4.2.1

BennyE$ curl -s -k -H "Content-Type: application/json" -H "Ov-App-Version:4.2.1.R01" -X POST -d '{"userName":"admin","password":"PASSWORD"}' https://192.168.40.12/api/login | jq .
{
  "message": "login.success",
  "accessToken": "Authorization: 450d7a34-5dc7-4f1e-a01f-29556864eb59"
}

Alle OmniVista bekannten Geräte anzeigen

Die Ausgabe beinhaltet SNMPv3 und ähnliche Zugangsdaten, man sollte also entsprechend vorsichtig mit dieser Liste umgehen!

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" https://192.168.40.12/api/devices | jq .
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "ArrayList",
  "response": [
    {
      "deviceType": "ArubaController",
      "name": "OAW4550",
      "ipAddress": "192.168.20.51",
      "model": null,
      "version": "6.4.4.9_55980",
      "location": "Showroom Kornwestheim",
      "deviceDNS": "oaw4550.alu4u.local",
      "deviceLastUpgradeStatus": "",
      "backupDate": null,
      "backupVersion": null,
      "lastKnownUpAt": 1473536311964,
      "description": "AOS-W (MODEL: OAW-4550), Version 6.4.4.9 (55980)",
      "status": "Up",
      "traps": "Not Configurable",
      "seenBy": "Default,Writers,Administrators,Network Administrators",
      "runningFrom": null,
      "changes": " ",
      "discoveredDateTime": 1470741969751,
      "macAddress": "00:1a:1e:01:05:58",
...

Anlegen einer neuen statischen Map (ohne Hintergrundbild)

Eine neue Map anzulegen ist es umfangreicher. Das folgende Format sorgt dafür dass alle Anforderungen der API, z.B. an multipart/form-data mit korrekter Boundary erfüllt sind. Man muss also die Information zum Hintergrundbild übergeben, obwohl man gar keines haben möchte.

Eine Map kann nur vom Benutzer „admin“ angelegt werden.

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -F "file=null" -F map='{ "TopologyMapVO": { "version": 0, "mapName": "Unprovisioned Devices", "backgroundImage": "", "backgroundImageUrl": "", "backgroundColor": "",  "filter": null, "dynamicMap": false, "physicalNetworkMap": false, "autoCreatedDynamicMap": false, "ownerInfo": "", "mapNodeCollection": { "nodeList": [ ] } } };type=application/json' https://192.168.40.12/api/topology/maps | jq .
{
  "status": "SUCCESS",
  "statusCode": 201,
  "type": "TopologyBaseResponse",
  "response": {
    "multipleResult": false,
    "resultList": [],
    "operation": "CREATE",
    "uniqueName": "57d404d3e4b0d545f07f47db",
    "displayName": "Unprovisioned Devices",
    "mapVersion": null,
    "success": true,
    "message": {
      "params": [
        "Unprovisioned Devices"
      ],
      "code": "topology.db.create.map.success"
    },
    "additionParams": {},
    "translated": {
      "additionParams": {},
      "operationTranslated": "CREATE",
      "successTranslated": "Success",
      "resultList": [],
      "messageTranslated": "Successfully created map Unprovisioned Devices"
    }
  },
  "serverVersion": "4.2.1.R01"
}

Anlegen einer neuen statischen Map (mit Hintergrundbild)

Die Datei „Picture1.png“ muss natürlich auch für den Upload zur Verfügung stehen, siehe erster -F Eintrag, „file=“. Im zweiten -F Eintrag „map=“ muss bei backgroundImage der Dateiname auch noch hinzugefügt werden.

Eine Map kann nur vom Benutzer „admin“ angelegt werden.

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -F "file=@Picture1.png" -F map='{ "TopologyMapVO": { "version": 0, "mapName": "Unprovisioned Devices Picture", "backgroundImage": "Picture1.png", "backgroundImageUrl": "", "backgroundColor": "",  "filter": null, "dynamicMap": false, "physicalNetworkMap": false, "autoCreatedDynamicMap": false, "ownerInfo": "", "mapNodeCollection": { "nodeList": [ ] } } };type=application/json' https://192.168.40.12/api/topology/maps | jq .
{
  "status": "SUCCESS",
  "statusCode": 201,
  "type": "TopologyBaseResponse",
  "response": {
    "multipleResult": false,
    "resultList": [],
    "operation": "CREATE",
    "uniqueName": "57d40e32e4b0d545f07f47de",
    "displayName": "Unprovisioned Devices Picture",
    "mapVersion": null,
    "success": true,
    "message": {
      "params": [
        "Unprovisioned Devices Picture"
      ],
      "code": "topology.db.create.map.success"
    },
    "additionParams": {},
    "translated": {
      "additionParams": {},
      "operationTranslated": "CREATE",
      "successTranslated": "Success",
      "resultList": [],
      "messageTranslated": "Successfully created map Unprovisioned Devices Picture"
    }
  },
  "serverVersion": "4.2.1.R01"
}

Alle Maps anzeigen

Alle Benutzer können sich eine Liste der Maps ausgeben lassen.

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" https://192.168.40.12/api/topology/maps/mapIds | jq .
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "ArrayList",
  "response": [
    {
      "instanceid": "57a9a194e4b0bf325ef8540d",
      "mapName": "Physical Network",
      "dynamicMap": false,
      "physicalNetworkMap": true,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57a9bdc6e4b0fa2ef20478ed",
      "mapName": "192.168.20.1-192.168.20.254",
      "dynamicMap": true,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57beb311e4b0d545f07f4745",
      "mapName": "Vorstand",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d3d49ce4b0d545f07f47c4",
      "mapName": "test",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d3d604e4b0d545f07f47c9",
      "mapName": "test2",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d3d7afe4b0d545f07f47ca",
      "mapName": "test3",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d3d8c9e4b0d545f07f47cb",
      "mapName": "test4",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d404d3e4b0d545f07f47db",
      "mapName": "Unprovisioned Devices",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57a9a47ae4b0fa2ef20478de",
      "mapName": "192.168.200.1-192.168.200.254",
      "dynamicMap": true,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d3dbd8e4b0d545f07f47cf",
      "mapName": "Unprovisioned Devices w picture",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d3dc8fe4b0d545f07f47d0",
      "mapName": "Unprovisioned Devices 2 w picture",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    },
    {
      "instanceid": "57d40e32e4b0d545f07f47de",
      "mapName": "Unprovisioned Devices Picture",
      "dynamicMap": false,
      "physicalNetworkMap": false,
      "autoCreatedDynamicMap": false,
      "translated": {}
    }
  ],
  "serverVersion": "4.2.1.R01"
}

Eine Maps löschen

Eine Map kann nur vom Benutzer „admin“ gelöscht werden.

Maps werden einzeln gelöscht, die „instanceid“ aus der vorherigen Ausgabe ist dabei das Ziel des DELETE Aufrufs.

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -X DELETE https://192.168.40.12/api/topology/maps/57d3dc8fe4b0d545f07f47d0 | jq . 
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "TopologyBaseResponse",
  "response": {
    "multipleResult": false,
    "resultList": [],
    "operation": "DELETE",
    "uniqueName": "57d3dc8fe4b0d545f07f47d0",
    "displayName": "Unprovisioned Devices 2 w picture",
    "mapVersion": null,
    "success": true,
    "message": {
      "params": [
        "Unprovisioned Devices 2 w picture"
      ],
      "code": "topology.db.delete.map.success"
    },
    "additionParams": {},
    "translated": {
      "additionParams": {},
      "operationTranslated": "DELETE",
      "successTranslated": "Success",
      "resultList": [],
      "messageTranslated": "Successfully deleted map Unprovisioned Devices 2 w picture"
    }
  },
  "serverVersion": "4.2.1.R01"
}

Ein Element suchen

Wir suchen nach „OS6860“ auf allen Maps (searchOnCurrentMap = false) und geben auch keine mapID an.

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '{ "TopologySearchRequest": {"searchString": "OS6860", "searchOnCurrentMap": false, "mapId": ""} }' https://192.168.40.12/api/topology/maps/search | jq .
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "TopologySearchResponse",
  "response": {
    "searchString": "OS6860",
    "searchOnCurrentMap": false,
    "mapId": "",
    "searchResultList": [
      {
        "NodeSearchResult": {
          "mapId": {
            "TopologyMapIdVO": {
              "instanceid": "57a9a194e4b0bf325ef8540d",
              "mapName": "Physical Network",
              "dynamicMap": false,
              "physicalNetworkMap": true,
              "autoCreatedDynamicMap": true,
              "translated": {}
            }
          },
          "node": {
            "id": "57b4de1de4b0ec43d27f6a6d",
            "x": 0,
            "y": 0,
            "deviceAddress": true,
            "mapId": "57a9bdc6e4b0fa2ef20478ed",
            "deviceName": "OS6860E-P24",
            "deviceIpAddress": "192.168.20.254",
            "deviceMacAddress": "e8:e7:32:ea:45:ed",
            "deviceType": "OS6860E-P24",
            "deviceVersion": "8.2.1.304.R01",
            "deviceStatus": "Down",
            "deviceDNS": "os6860.alu4u.local",
            "deviceLocation": "Showroom Kornwestheim",
            "deviceLastUpgradeStatus": "",
            "deviceBackupDate": null,
            "deviceBackupVersion": null,
            "deviceLastKnownUpAt": 1472124658902,
            "deviceDescription": "Alcatel-Lucent OS6860E-P24 8.2.1.304.R01 Service Release, May 17, 2016.",
            "deviceTraps": "Unknown",
            "deviceRunningFrom": "821-304-R01",
            "deviceChanges": "Unsaved",
            "deviceDiscoveredDate": 1471471133187,
            "webUrl": "https://192.168.20.254/",
            "deviceIconUrl": "topology/deviceicons/6860.png",
            "deviceIconName": "6860",
            "licenseType": "Alcatel-Lucent Enterprise",
            "friendlyName": "192.168.20.254",
            "supportsSsh": true,
            "arubaWireLessOrThirdPartyDevice": false,
            "oaw": false,
            "others": {
              "SwitchState": 5,
              "SwitchSysObjId": ".1.3.6.1.4.1.6486.801.1.1.2.1.11.1.6",
              "coreLicenseUsed": 1,
              "SwitchFtpLoginPasswd": "Isklaaaa :)",
              "SwitchContact": "Michael Neesen",
              "ChassisName": "OS6860E-P24",
              "SwitchFtpLoginName": "admin",
              "SwitchSynchronized": "Synchronize"
            },
            "switchState": "SWITCH_STATE_MAJOR",
            "overlayType": "none",
            "stackOverlay": null,
            "virtualChassisOverlay": null,
            "wirelessOverlay": null,
            "translated": {
              "switchStateTranslated": "SWITCH_STATE_MAJOR",
              "deviceStatusTranslated": "Down",
              "yTranslated": "0",
              "deviceLastKnownUpAtTranslated": "Aug 25, 2016 1:30:58 PM",
              "deviceDiscoveredDateTranslated": "Aug 17, 2016 11:58:53 PM",
              "xTranslated": "0"
            }
          },
          "translated": {}
        }
      },
      {
        "NodeSearchResult": {
          "mapId": {
            "TopologyMapIdVO": {
              "instanceid": "57a9bdc6e4b0fa2ef20478ed",
              "mapName": "192.168.20.1-192.168.20.254",
              "dynamicMap": true,
              "physicalNetworkMap": false,
              "autoCreatedDynamicMap": false,
              "translated": {}
            }
          },
          "node": {
            "id": "57b4de1de4b0ec43d27f6a6d",
            "x": 0,
            "y": 0,
            "deviceAddress": true,
            "mapId": "57a9bdc6e4b0fa2ef20478ed",
            "deviceName": "OS6860E-P24",
            "deviceIpAddress": "192.168.20.254",
            "deviceMacAddress": "e8:e7:32:ea:45:ed",
            "deviceType": "OS6860E-P24",
            "deviceVersion": "8.2.1.304.R01",
            "deviceStatus": "Down",
            "deviceDNS": "os6860.alu4u.local",
            "deviceLocation": "Showroom Kornwestheim",
            "deviceLastUpgradeStatus": "",
            "deviceBackupDate": null,
            "deviceBackupVersion": null,
            "deviceLastKnownUpAt": 1472124658902,
            "deviceDescription": "Alcatel-Lucent OS6860E-P24 8.2.1.304.R01 Service Release, May 17, 2016.",
            "deviceTraps": "Unknown",
            "deviceRunningFrom": "821-304-R01",
            "deviceChanges": "Unsaved",
            "deviceDiscoveredDate": 1471471133187,
            "webUrl": "https://192.168.20.254/",
            "deviceIconUrl": "topology/deviceicons/6860.png",
            "deviceIconName": "6860",
            "licenseType": "Alcatel-Lucent Enterprise",
            "friendlyName": "192.168.20.254",
            "supportsSsh": true,
            "arubaWireLessOrThirdPartyDevice": false,
            "oaw": false,
            "others": {
              "SwitchState": 5,
              "SwitchSysObjId": ".1.3.6.1.4.1.6486.801.1.1.2.1.11.1.6",
              "coreLicenseUsed": 1,
              "SwitchFtpLoginPasswd": "Isklaaaa :)",
              "SwitchContact": "Michael Neesen",
              "ChassisName": "OS6860E-P24",
              "SwitchFtpLoginName": "admin",
              "SwitchSynchronized": "Synchronize"
            },
            "switchState": "SWITCH_STATE_MAJOR",
            "overlayType": "none",
            "stackOverlay": null,
            "virtualChassisOverlay": null,
            "wirelessOverlay": null,
            "translated": {
              "switchStateTranslated": "SWITCH_STATE_MAJOR",
              "deviceStatusTranslated": "Down",
              "yTranslated": "0",
              "deviceLastKnownUpAtTranslated": "Aug 25, 2016 1:30:58 PM",
              "deviceDiscoveredDateTranslated": "Aug 17, 2016 11:58:53 PM",
              "xTranslated": "0"
            }
          },
          "translated": {}
        }
      }
    ],
    "translated": {
      "mapIdTranslated": "",
      "searchOnCurrentMapTranslated": "false",
      "searchStringTranslated": "OS6860",
      "searchResultList": []
    }
  },
  "serverVersion": "4.2.1.R01"
}

Alle Hintergrundbilder der Maps auflisten

Bei mir relativ langweilig, hab leider keine Hintergrundbilder mehr derzeit.

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" https://192.168.40.12/api/topology/maps/bg | jq .
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "ArrayList",
  "response": [],
  "serverVersion": "4.2.1.R01"
}

Alle Elemente einer Map auflisten

Wer hier den Inhalt mehrerer Maps sehen möchte, übermittelt einfach [ „57a9bdc6e4b0fa2ef20478ed“, „instanceid-der-zweiten-Map“, „instanceid-der-dritten-Map“ ].

BennyE$ curl -s -k -H "Authorization: Bearer 5827823e-9979-4d93-851b-4aa71e9e44eb" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '[ "57a9bdc6e4b0fa2ef20478ed" ]' https://192.168.40.12/api/topology/maps/nodes
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "MapNodeCollectionVO",
  "response": {
    "nodeList": [
      {
        "id": "57a9bdcbe4b0bf325ef855ed",
        "x": 0,
        "y": 0,
        "deviceAddress": true,
        "mapId": "57a9bdc6e4b0fa2ef20478ed",
        "deviceName": "OS6450-24",
        "deviceIpAddress": "192.168.20.35",
        "deviceMacAddress": "e8:e7:32:40:28:e0",
        "deviceType": "OS6450-C24",
        "deviceVersion": "6.7.1.86.R03",
        "deviceStatus": "Up",
        "deviceDNS": "os6450-24.alu4u.local",
        "deviceLocation": "Lab ProfServ Kornwestheim",
        "deviceLastUpgradeStatus": "Failed (Image)",
        "deviceBackupDate": null,
        "deviceBackupVersion": null,
        "deviceLastKnownUpAt": 1473523589767,
        "deviceDescription": "Alcatel-Lucent OS6450-24 6.7.1.86.R03 GA, August 10, 2016.",
        "deviceTraps": "Unknown",
        "deviceRunningFrom": "working",
        "deviceChanges": "Unsaved",
        "deviceDiscoveredDate": 1470741963808,
        "webUrl": "https://192.168.20.35/",
        "deviceIconUrl": "topology/deviceicons/6450.png",
        "deviceIconName": "6450",
        "licenseType": "Alcatel-Lucent Enterprise",
        "friendlyName": "192.168.20.35",
        "supportsSsh": true,
        "arubaWireLessOrThirdPartyDevice": false,
        "oaw": false,
        "others": {
          "SwitchState": 1,
          "SwitchSysObjId": ".1.3.6.1.4.1.6486.800.1.1.2.1.12.1.5",
          "coreLicenseUsed": 1,
          "SwitchFtpLoginPasswd": "blubblubblub",
          "SwitchContact": "Michael Neesen",
          "ChassisName": "OS6450-C24",
          "SwitchFtpLoginName": "admin",
          "SwitchSynchronized": "Not Applicable"
        },
        "switchState": "SWITCH_STATE_OK",
        "overlayType": "none",
        "stackOverlay": null,
        "virtualChassisOverlay": null,
        "wirelessOverlay": null,
        "translated": {
          "switchStateTranslated": "SWITCH_STATE_OK",
          "deviceStatusTranslated": "Up",
          "yTranslated": "0",
          "deviceLastKnownUpAtTranslated": "Sep 10, 2016 6:06:29 PM",
          "deviceDiscoveredDateTranslated": "Aug 9, 2016 1:26:03 PM",
          "xTranslated": "0"
        }
      },
... 
}

Statistik einer Map anzeigen

Das funktioniert anscheinend nur wenn man hier Geräte und Links mit angibt.

TODO: Benny

BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '{ "TopologyStatisticRequest": { "mapId": "56c2cee507e12d333c0f442f", "devicesIp": [], "linksId": [] } }' https://192.168.40.12/api/topology/maps/57a9bdc6e4b0fa2ef20478ed/statisticv2 | jq .
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "TopologyStatisticResponse",
  "response": {
    "mapId": "56c2cee507e12d333c0f442f",
    "switchStatusStatistic": [
      {
        "type": "Up",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Up"
        }
      },
      {
        "type": "Down",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Down"
        }
      },
      {
        "type": "Warning",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Warning"
        }
      }
    ],
    "linkStatusStatistic": [
      {
        "type": "LINK_UP",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "up"
        }
      },
      {
        "type": "LINK_DOWN",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "down"
        }
      },
      {
        "type": "LINK_BLOCKED",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "blocked"
        }
      },
      {
        "type": "LINK_UNKNOWN",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "unknown"
        }
      }
    ],
    "deviceTypesStatistic": [
      {
        "type": "virtualchassis",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "virtualchassis"
        }
      },
      {
        "type": "stack",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "stack"
        }
      },
      {
        "type": "oaw",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "oaw"
        }
      }
    ],
    "linkTypesStatistic": [
      {
        "type": "linkagg",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "linkagg"
        }
      }
    ],
    "linkOriginStatistic": [
      {
        "type": "ORIGIN_LLDP",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "LLDP"
        }
      },
      {
        "type": "ORIGIN_MANUAL",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "MANUAL"
        }
      },
      {
        "type": "ORIGIN_XMAP",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "XMAP"
        }
      },
      {
        "type": "ORIGIN_AMAP",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "AMAP"
        }
      },
      {
        "type": "ORIGIN_PNNI",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "PNNI"
        }
      },
      {
        "type": "ORIGIN_OEM",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "OEM"
        }
      },
      {
        "type": "ORIGIN_SPB",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "SPB"
        }
      }
    ],
    "switchStateStatistic": [
      {
        "type": "SWITCH_STATE_OK",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "SWITCH_STATE_OK"
        }
      },
      {
        "type": "SWITCH_STATE_WARNING",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "SWITCH_STATE_WARNING"
        }
      },
      {
        "type": "SWITCH_STATE_MINOR",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "SWITCH_STATE_MINOR"
        }
      },
      {
        "type": "SWITCH_STATE_MAJOR",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "SWITCH_STATE_MAJOR"
        }
      },
      {
        "type": "SWITCH_STATE_CRITICAL",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "SWITCH_STATE_CRITICAL"
        }
      }
    ],
    "switchChangesStatistic": [
      {
        "type": "Unknown",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Unknown"
        }
      },
      {
        "type": "none",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "none"
        }
      },
      {
        "type": "Unsaved",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Unsaved"
        }
      },
      {
        "type": "Saved",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Saved"
        }
      },
      {
        "type": "Certified",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Certified"
        }
      },
      {
        "type": "Uncertified",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Uncertified"
        }
      }
    ],
    "switchSynchronizedStatistic": [
      {
        "type": "Unknown",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Unknown"
        }
      },
      {
        "type": "NotApplicable",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "NotApplicable"
        }
      },
      {
        "type": "NotSynchronize",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "NotSynchronize"
        }
      },
      {
        "type": "Synchronize",
        "count": 0,
        "translated": {
          "countTranslated": "0",
          "typeTranslated": "Synchronize"
        }
      }
    ],
    "translated": {
      "deviceTypesStatistic": [],
      "switchSynchronizedStatistic": [],
      "linkTypesStatistic": [],
      "switchStateStatistic": [],
      "switchStatusStatistic": [],
      "mapIdTranslated": "56c2cee507e12d333c0f442f",
      "switchChangesStatistic": [],
      "linkOriginStatistic": [],
      "linkStatusStatistic": []
    }
  },
  "serverVersion": "4.2.1.R01"
}

Manuell ein Gerät aufnehmen (und einer Map zuordnen => geht aktuell nicht, siehe nächster Punkt)

Work in progress! Funktioniert noch nicht so wie ich mir das vorstelle.

  • Das Gerät dass man aufnehmen möchte muss erreichbar sein, sonst dauert der Request sehr lange bis zur JSON-Response (knapp eine Minute)
  • MD5+DES ist das Protokoll 5, nicht 7 wie es die Ausgabe unter /api/devices einem glauben machen will (7 ist SHA+AES192) :: Anfrage bei R&D offen.
  • Egal was man als „currentMap“ übergibt, das Gerät landet immer in „Physical Devices“ :: Anfrage bei R&D offen.
#BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '' https://192.168.40.12/api/discoverylite/devices | jq .
 
BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '{ "ipAddress": "1.1.1.1", "discoveryProfile": { "name": "Benny_API_Test", "seenBy": [ "Port Administrators", "Default", "Administrators", "Writers", "Network Administrators" ], "telnetOrFTPUser": "admin", "telnetOrFTPPassword": "switch", "secondaryPassword": "", "snmpProfile": { "type": "SnmpProfile", "snmpVersion": "SNMPv2", "readSnmpCommunity": "public", "writeSnmpCommunity": "private", "snmpv3Information": { "contextId": "", "contextName": "", "securityName": "", "authProtocol": null, "authPassword": "", "privPassword": "" }, "maxRetries": 3, "timeout": 5000 }, "trapStationUserName": "", "discoverLinks": "Normally", "shellPreference": "Telnet", "useGetbulk": true, "maxRepetitions": 10, "allowPortDisabling": false }, "currentMap": "57d404d3e4b0d545f07f47db" }' https://192.168.40.12/api/discoverylite/devices | jq .
{
  "status": "SUCCESS",
  "statusCode": 201,
  "type": "DiscoverySuccessResponse",
  "response": {
    "sessionId": null,
    "user": null,
    "currentTypeDiscovery": null,
    "message": {
      "params": [],
      "code": "disc.create.success"
    },
    "translated": {
      "messageTranslated": "Created successfully"
    }
  },
  "serverVersion": "4.2.1.R01"
}
 
### Kopie des JSON-Request-Body als Oneliner
 
{ "ipAddress": "1.1.1.1", "discoveryProfile": { "name": "Benny_API_Test", "seenBy": [ "Port Administrators", "Default", "Administrators", "Writers", "Network Administrators" ], "telnetOrFTPUser": "admin", "telnetOrFTPPassword": "switch", "secondaryPassword": "", "snmpProfile": { "type": "SnmpProfile", "snmpVersion": "SNMPv2", "readSnmpCommunity": "public", "writeSnmpCommunity": "private", "snmpv3Information": { "contextId": "", 
"contextName": "", "securityName": "", "authProtocol": null, "authPassword": "", "privPassword": "" }, "maxRetries": 3, "timeout": 5000 }, "trapStationUserName": "", "discoverLinks": "Normally", "shellPreference": "Telnet", "useGetbulk": true, "maxRepetitions": 10, "allowPortDisabling": false }, "currentMap": "57d404d3e4b0d545f07f47db" }
 
### prettyprint JSON-Request-Body 
 
{
    "ipAddress""1.1.1.1",
    "discoveryProfile": {
        "name""Benny_API_Test",
        "seenBy": [
            "Port Administrators",
            "Default",
            "Administrators",
            "Writers",
            "Network Administrators"
        ],
        "telnetOrFTPUser""admin",
        "telnetOrFTPPassword""switch",
        "secondaryPassword""",
        "snmpProfile": {
            "type""SnmpProfile",
            "snmpVersion""SNMPv2",
            "readSnmpCommunity""public",
            "writeSnmpCommunity""private",
            "snmpv3Information": {
                "contextId""",
                "contextName""",
                "securityName""",
                "authProtocol": null,
                "authPassword""",
                "privPassword"""
            },
            "maxRetries"3,
            "timeout"5000
        },
        "trapStationUserName""",
        "discoverLinks""Normally",
        "shellPreference""Telnet",
        "useGetbulk"true,
        "maxRepetitions"10,
        "allowPortDisabling"false
    },
    "currentMap""57d404d3e4b0d545f07f47db"
}
 
#### Funktioniert für MD5+DES (5), warum das aber in dem anderen Output (7) ist muss ich noch rausfinden
 
curl -s -k -H "Authorization: Bearer 606caa63-5238-451b-b2b4-6fa6efc402fe" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '{ "ipAddress": "192.168.20.26", "discoveryProfile": { "name": "Benny_API_Test", "seenBy": [ "Port Administrators", "Default", "Administrators", "Writers", "Network Administrators" ], "telnetOrFTPUser": "admin", "telnetOrFTPPassword": "switch", "secondaryPassword": "", "snmpProfile": { "type": "SnmpProfile", "snmpVersion": "SNMPv3", "readSnmpCommunity": "", "writeSnmpCommunity": "", "snmpv3Information": { "contextId": "", "contextName": "", "securityName": "USERNAME (z.B. omnivista) ", "authProtocol": 5, "authPassword": "PASSWORD", "privPassword": "PASSWORD" }, "maxRetries": 3, "timeout": 5000 }, "trapStationUserName": "", "discoverLinks": "Normally", "shellPreference": "Telnet", "useGetbulk": true, "maxRepetitions": 10, "allowPortDisabling": false }, "currentMap": "57d404d3e4b0d545f07f47db" }' https://192.168.40.12/api/discoverylite/devices

Gerät einer Map zuordnen

  • mapId ist die ID der Zielmap (im JSON-Request-Body und der URL!)
  • id ist die instanceid des Objekts das man auf Map hinzufügen möchte
  • deviceIPAddress ist die IP des Gerätes das der Map hinzugefügt werden soll (kann ja mehrere haben, das wird dann wohl die primäre für diese Map)
BennyE$ curl -s -k -H "Authorization: Bearer 450d7a34-5dc7-4f1e-a01f-29556864eb59" -H "Ov-App-Version:4.2.1.R01" -H "Content-Type: application/json" -X POST -d '[ { "id": "57d48039e4b0ec43d29869ac", "deviceIpAddress": "192.168.20.26", "x": 0, "y": 120, "deviceAddress": true, "mapId": "57d404d3e4b0d545f07f47db" } ]' https://192.168.40.12/api/topology/maps/57d404d3e4b0d545f07f47db/addNodes/ | jq .
{
  "status": "SUCCESS",
  "statusCode": 200,
  "type": "TopologyBaseResponse",
  "response": {
    "multipleResult": false,
    "resultList": [],
    "operation": "ADDNODESTOMAP",
    "uniqueName": "57d404d3e4b0d545f07f47db",
    "displayName": "Unprovisioned Devices",
    "mapVersion": 1,
    "success": true,
    "message": {
      "params": [],
      "code": "topology.addnodestomap.success"
    },
    "additionParams": {},
    "translated": {
      "additionParams": {},
      "operationTranslated": "ADDNODESTOMAP",
      "successTranslated": "Success",
      "resultList": [],
      "messageTranslated": "Added devices to map successfully"
    }
  },
  "serverVersion": "4.2.1.R01"
}
 
### json oneliner
 
[ { "id": "57d48039e4b0ec43d29869ac", "deviceIpAddress": "192.168.20.26", "x": 0, "y": 120, "deviceAddress": true, "mapId": "57d404d3e4b0d545f07f47db" } ]
 
### prettyprint
 
[
    {
        "id": "57d48039e4b0ec43d29869ac", 
        "deviceIpAddress": "192.168.20.26", 
        "x": 0, 
        "y": 120, 
        "deviceAddress": true, 
        "mapId": "57d404d3e4b0d545f07f47db"
    }
]

Feierabend nun: RESTful API, you gonna be restLESS! :)

OmniVista RESTful API mit Python ansprechen

Meine Versuche mit cURL haben mir gezeigt dass für Python noch einiges anders laufen muss. Kümmere mich bei nächster Gelegenheit darum das zu entwickeln.

import requests
import json
 
# Dieser Code geht sicherlich schoener, aber fuer den Moment ist das nur POC
 
ovurl = "https://192.168.5.10"
a = requests.Session()
 
# Boese, niemals verify=False in Produktion!
#b = a.post(ovurl + "/api/login", verify=False)
 
rbody = {
'userName': 'admin',
'password': 'your_password'
}
 
header = {
"content-type": "application/json"
}
 
# Boese, niemals verify=False in Produktion!
# "data" nur als json-Format uebergeben
b = a.post(ovurl + "/api/login", data=json.dumps(rbody), verify=False, headers=header)
#>>> b
#<Response [200]>
 
#>>> b.text
#'{"message":"login.success","accessToken":"dc51d6f3-f8e8-4f66-adbd-c251307714aa"}'
 
c = a.get(ovurl + "/api/devices", verify=False, headers=header)
 
# Wer sich wundert dass dies einfach funktioniert ..
# Es gibt einen Cookie mit dem accessToken
 
#>>> a.cookies
#<RequestsCookieJar[Cookie(version=0, name='JSESSIONID', value='00AFEF32E0503727756885368419BC17', port=None, port_specified=False, domain='192.168.5.10', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='accessToken', value='dc51d6f3-f8e8-4f66-adbd-c251307714aa', port=None, port_specified=False, domain='192.168.5.10', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)]>
 
 
parsed = json.loads(c.text)
print(json.dumps(parsed, indent=4))
omnivista-restful-api.txt · Zuletzt geändert: 2024/06/09 10:29 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki