cisco-en-programmability / dnacentersdk

Cisco DNA Center Python SDK
https://dnacentersdk.readthedocs.io/en/latest/
MIT License
70 stars 33 forks source link

Create Syslog Event Subscription SDK API giving Parsing error in the response while with same payload able to create notification in GUI. #151

Closed Abhishek-121 closed 4 months ago

Abhishek-121 commented 4 months ago

Prerequisites

Describe the bug

While working on automation of creating the Syslog Event Notification using Ansible, I encountered an issue in the SDK API 'create_syslog_event_subscription' return response and using the same payload I am able to create the Syslog Notification in DNAC (Platform --> Developer Toolkit).

Dnacentersdk version - 2.9.1 API Used - ('/dna/intent/api/v1/event/subscription/syslog')

Payload passed to the 'create_syslog_event_subscription' API -

[ { "name": "Syslog playbook demo", "subscriptionEndpoints": [ { "instanceId": "fc0e6daa-2b15-4ee5-b509-e3268b43d497", "subscriptionDetails": { "connectorType": "SYSLOG" } } ], "filter": { "eventIds": [ "NETWORK-DEVICES-3-107", "NETWORK-DEVICES-3-105" ], "siteIds": [ "bf561bf3-95d6-4da1-bf49-26887955fa2e", "69f31d51-9e0d-48f4-8546-4935253f9a67" ] } } ]

With the above payload only I am able to create Syslog Notification Event using the API Create Syslog Event Subscription present in DNAC --> Platform --> Developer Tookit.

When I execute the playbook, I got this error from the API response -

console_syslog_event
**{
    "errorMessage": {
        "errors": ["Parsing EventSubscription failed due to No content to map due to end-of-input\n at [Source: (String)\"\"; line: 1, column: 0]"]
        },
        "apiStatus": "FAILURE",
        "statusMessage": null
}**

Expected behavior As per the Cisco Catalyst GUI we can create Syslog Event Notification, so we are expecting the same using the Ansible by passing input in the playbook.

Screenshots

Syslog Event

Environment (please complete the following information):

Additional context Add any other context about the problem here.

bvargasre commented 4 months ago

Hi @Abhishek-121 same here, activate the debug and send me all the output I tried with the payload that you passed and it did not give me an error.

payload = [
    {
        "name": "Syslog playbook demo",
        "subscriptionEndpoints": [
            {
                "instanceId": "fc0e6daa-2b15-4ee5-b509-e3268b43d497",
                "subscriptionDetails": {
                    "connectorType": "SYSLOG"
                }
            }
        ],
        "filter": {
            "eventIds": [
                "NETWORK-DEVICES-3-107",
                "NETWORK-DEVICES-3-105"
            ],
            "siteIds": [
                "bf561bf3-95d6-4da1-bf49-26887955fa2e",
                "69f31d51-9e0d-48f4-8546-4935253f9a67"
            ]
        }
    }
]

try:
    response = dnac.event_management.create_syslog_event_subscription(payload=payload)
    print(response)
except Exception as e:
    print("Error: ", e)
Attempt 1

Request
        URL: https://{}/dna/intent/api/v1/event/subscription/syslog
        Method: POST
        Headers: 
                User-Agent: python-requests/2.27.1
                Accept-Encoding: gzip, deflate
                Accept: */*
                Connection: keep-alive
                X-Auth-Token: eyJhbGciOiJSUzI1NiIsInR5cCI6Ik
                Content-type: application/json;charset=utf-8
        Params:
              {}
        Body:
            [
                {
                    "name": "Syslog playbook demo",
                    "subscriptionEndpoints": [
                        {
                            "instanceId": "fc0e6daa-2b15-4ee5-b509-e3268b43d497",
                            "subscriptionDetails": {
                                "connectorType": "SYSLOG"
                            }
                        }
                    ],
                    "filter": {
                        "eventIds": [
                            "NETWORK-DEVICES-3-107",
                            "NETWORK-DEVICES-3-105"
                        ],
                        "siteIds": [
                            "bf561bf3-95d6-4da1-bf49-26887955fa2e",
                            "69f31d51-9e0d-48f4-8546-4935253f9a67"
                        ]
                    }
                }
            ]

Response
        Status: 202 - Accepted
        Headers: 
                Content-Type: application/json
                Content-Length: 88
                Connection: keep-alive
                Date: Thu, 09 May 2024 21:20:35 GMT
                X-Correlation-Id: bbf3ebc3-d8dd-4a16-8a2e-ef0056a32620
                Via: api-gateway
                Cache-Control: no-store
                Pragma: no-cache
                Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' blob: data:
                X-Content-Type-Options: nosniff
                X-XSS-Protection: 1
                Strict-Transport-Security: max-age=31536000; includeSubDomains
                X-Frame-Options: SAMEORIGIN
        Body:
             {
                 "statusUri": "/dna/intent/api/v1/event/api-status/ee997933-7d53-4465-b72c-b7db6804cb70"
             }
{'statusUri': '/dna/intent/api/v1/event/api-status/ee997933-7d53-4465-b72c-b7db6804cb70'}
Abhishek-121 commented 4 months ago

Hi @bvargasre, attaching log file for your reference for creating syslog event subscription.

events_log_output.log

You can check the payload by filtering the given string - "Requested payload for create_syslog_event_subscription"

Abhishek-121 commented 4 months ago

Hi @bvargasre , this issue gets fixed as it required some changed in the payload while calling the sdk. We can close this issue.