Update work/tbx/meraki/meraki_sandbox_api.md
This commit is contained in:
@@ -536,4 +536,187 @@ if __name__ == '__main__':
|
|||||||
python scripts/clientcount.py -k $MERAKI_DASHBOARD_API_KEY -o "DeLab"
|
python scripts/clientcount.py -k $MERAKI_DASHBOARD_API_KEY -o "DeLab"
|
||||||
```
|
```
|
||||||
|
|
||||||
This script should now handle API rate limits more gracefully by retrying failed requests with exponential backoff. If you continue to encounter issues, please provide the specific error message for further assistance.
|
This script should now handle API rate limits more gracefully by retrying failed requests with exponential backoff. If you continue to encounter issues, please provide the specific error message for further assistance.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Meraki's custom payload templates for webhooks offer a powerful way to integrate directly with any REST API service by shaping the webhook body and headers as needed. This can significantly simplify and reduce the cost of integrating Meraki alerts with third-party services. Here are some brainstorming ideas and concepts to explore:
|
||||||
|
|
||||||
|
### 1. Direct Integration with Third-Party APIs
|
||||||
|
|
||||||
|
**Use Case:** Integrate Meraki alerts directly with a third-party event logging service without the need for an intermediary service.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
**Webhook Configuration:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "Event Logger",
|
||||||
|
"url": "https://someservice.com/api/events",
|
||||||
|
"sharedSecret": "00sOmEAuthToKen000",
|
||||||
|
"payloadTemplate": {
|
||||||
|
"payloadTemplateId": "wpt_00003",
|
||||||
|
"name": "logservice"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers Template (headers.liquid):**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"Authorization": "Bearer {{sharedSecret}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body Template (body.liquid):**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"summary": "{{alertType}}",
|
||||||
|
"severity": "{{alertLevel}}",
|
||||||
|
"details": "{{networkUrl}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Advanced Data Transformation with Liquid Templates
|
||||||
|
|
||||||
|
Leverage the Liquid template language to format and transform data within the webhook payload. This includes using variables, filters, and accessing nested properties.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
**Body Template with Liquid Filters (body.liquid):**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"summary": "{{alertType}}",
|
||||||
|
"severity": "{{alertLevel}}",
|
||||||
|
"details": "{{alertData | jsonify}}",
|
||||||
|
"timestamp": "{{occurredAt | date: '%Y-%m-%d %H:%M:%S'}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Simplifying Complex Integrations
|
||||||
|
|
||||||
|
Use custom payload templates to send structured data to services like Splunk, Datadog, or custom logging systems.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
**Splunk Integration:**
|
||||||
|
|
||||||
|
**Headers Template:**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"Authorization": "Splunk {{sharedSecret}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body Template:**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"event": {
|
||||||
|
"summary": "{{alertType}}",
|
||||||
|
"severity": "{{alertLevel}}",
|
||||||
|
"details": "{{alertData | json_markdown}}"
|
||||||
|
},
|
||||||
|
"source": "Meraki",
|
||||||
|
"sourcetype": "_json"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Automated Incident Response
|
||||||
|
|
||||||
|
Trigger automated incident responses by integrating Meraki webhooks with incident management tools like PagerDuty or ServiceNow.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
**PagerDuty Integration:**
|
||||||
|
|
||||||
|
**Headers Template:**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "Token token={{sharedSecret}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body Template:**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"payload": {
|
||||||
|
"summary": "{{alertType}} detected on {{networkName}}",
|
||||||
|
"severity": "{{alertLevel | downcase}}",
|
||||||
|
"source": "{{deviceName}}",
|
||||||
|
"component": "{{deviceModel}}",
|
||||||
|
"group": "{{networkName}}",
|
||||||
|
"class": "{{alertType}}",
|
||||||
|
"custom_details": {
|
||||||
|
"details": "{{alertData | json_markdown}}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routing_key": "{{pagerDutyRoutingKey}}",
|
||||||
|
"event_action": "trigger",
|
||||||
|
"client": "Meraki",
|
||||||
|
"client_url": "{{networkUrl}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Monitoring and Alert Enrichment
|
||||||
|
|
||||||
|
Enrich alerts with additional contextual information before sending them to monitoring systems.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
**Enriched Alert Template:**
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{
|
||||||
|
"summary": "{{alertType}}",
|
||||||
|
"severity": "{{alertLevel}}",
|
||||||
|
"details": "{{alertData | jsonify}}",
|
||||||
|
"device": {
|
||||||
|
"name": "{{deviceName}}",
|
||||||
|
"model": "{{deviceModel}}",
|
||||||
|
"mac": "{{deviceMac}}"
|
||||||
|
},
|
||||||
|
"network": {
|
||||||
|
"name": "{{networkName}}",
|
||||||
|
"url": "{{networkUrl}}"
|
||||||
|
},
|
||||||
|
"occurred_at": "{{occurredAt | date: '%Y-%m-%d %H:%M:%S'}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Data Validation and Testing
|
||||||
|
|
||||||
|
Use tools like Webhook.site, JSON Validator, and the Meraki Webhook Payload Builder to validate and test your webhook configurations and payloads.
|
||||||
|
|
||||||
|
**Example Workflow:**
|
||||||
|
|
||||||
|
1. **Create a Webhook Receiver:**
|
||||||
|
- Use Webhook.site to generate a unique URL for testing webhooks.
|
||||||
|
- Configure your Meraki webhook to send data to this URL.
|
||||||
|
|
||||||
|
2. **Validate JSON:**
|
||||||
|
- Use JSON Validator to ensure your payload templates are producing valid JSON.
|
||||||
|
|
||||||
|
3. **Build and Test Templates:**
|
||||||
|
- Use the Meraki Webhook Payload Builder to create and test your templates.
|
||||||
|
|
||||||
|
### Resources and Tools
|
||||||
|
|
||||||
|
- **[Liquid Docs](https://shopify.github.io/liquid/)**: Comprehensive documentation for the Liquid template language.
|
||||||
|
- **[Webhook.site](https://webhook.site/)**: A tool to test and inspect HTTP requests.
|
||||||
|
- **[JSON Formatter](https://jsonformatter.curiousconcept.com)**: Online utility to validate JSON.
|
||||||
|
- **[Postman](https://www.postman.com/)**: Manage Meraki API webhook related endpoints.
|
||||||
|
|
||||||
|
### Summary
|
||||||
|
|
||||||
|
By using Meraki's custom payload templates, you can streamline the integration process with third-party services, enrich your alerts with additional context, and reduce the need for intermediary services. The Liquid template language provides powerful tools to format and transform data, making it easy to meet the requirements of any REST API service. This approach not only simplifies the integration but also enhances the flexibility and scalability of your network monitoring and incident response processes.
|
||||||
|
|
||||||
|
If you have specific use cases or need more detailed examples, feel free to ask!
|
||||||
Reference in New Issue
Block a user