关于从New Relic获取数据至API Gateway及从New Relic应用调用API Gateway触发Lambda创建JIRA工单的可行性咨询
Hey Jay! Great questions—both of these are totally achievable with New Relic's tooling, and I’ve helped several teams set up similar workflows. Let’s walk through each scenario step by step:
There are a few reliable approaches to get data from New Relic to your API Gateway, depending on whether you need scheduled pulls or real-time pushes:
New Relic REST API + Custom Script/Service
New Relic exposes a full REST API that lets you pull metrics, events, logs, and entity data. You can build a simple script (Python, Node.js, etc.) or use a serverless function/cloud service to schedule regular calls to the New Relic API, then forward the retrieved data to your API Gateway. Here’s a quick Python example to illustrate:import requests # New Relic API config NR_API_KEY = "your_new_relic_user_api_key" NR_ACCOUNT_ID = "your_account_id" NR_METRICS_URL = f"https://api.newrelic.com/v2/metrics/data.json?account_id={NR_ACCOUNT_ID}" # API Gateway endpoint API_GATEWAY_URL = "your_api_gateway_endpoint" # Fetch data from New Relic nr_headers = {"X-Api-Key": NR_API_KEY} nr_response = requests.get(NR_METRICS_URL, headers=nr_headers) nr_data = nr_response.json() # Send data to API Gateway gateway_response = requests.post(API_GATEWAY_URL, json=nr_data) print(f"Gateway response status: {gateway_response.status_code}")You can host this script on a cron job, AWS Lambda (with CloudWatch Events scheduling), or any orchestration tool to run on a regular interval.
New Relic Data Forwarder
If you want real-time or scheduled pushes without writing custom code, use New Relic’s built-in Data Forwarder. This tool lets you configure rules to forward specific events, metrics, or logs directly to an HTTP endpoint (your API Gateway). You can set this up in New Relic One: navigate to Data Management > Forwarders, create a new forwarder, select the data types to send, input your API Gateway URL, and configure authentication (like API keys) if needed.New Relic Events API + Webhooks
For event-specific pushes (e.g., when a custom event is generated in New Relic), you can use the Events API combined with webhooks. Pair this with New Relic Alerts or Workflows to trigger a webhook to your API Gateway whenever the event occurs.
To automate JIRA ticket creation when New Relic detects issues, you’ll link New Relic’s alerting system to your API Gateway (which triggers the Lambda function). Here’s the most straightforward way:
New Relic Workflows (Recommended)
New Relic Workflows are designed for this kind of automation—they let you tie alert triggers to actions like webhooks. Here’s how to set it up:- In New Relic One, go to Automation > Workflows and click Create workflow.
- Set the trigger: Choose Alert as the trigger source, then select the alert rules you want to monitor (e.g., high error rates, service downtime).
- Add a webhook action: Select Webhook from the action menu, input your API Gateway endpoint URL, set the request method to
POST, and use New Relic’s built-in variables to populate the request body (e.g.,{"alert_title": "{{alert.title}}", "description": "{{alert.description}}", "impacted_service": "{{alert.entities.[0].name}}"}). - Save and enable the workflow. When an alert fires, New Relic will send the payload to your API Gateway, which triggers your Lambda function.
Lambda Function Logic
Your Lambda function will need to:- Parse the JSON payload sent from New Relic via API Gateway.
- Construct a JIRA ticket request using the JIRA REST API (endpoint:
/rest/api/3/issue). Include fields like project ID, issue type (e.g., Bug), summary (using the alert title), description (using alert details), and priority. - Authenticate with JIRA (using an API key and email, or OAuth).
- Send the request to JIRA and return a success/failure response to API Gateway.
Alternative: Legacy Alert Policies + Webhook Channels
If you’re using older New Relic Alert Policies, you can add a Webhook notification channel directly to the policy. Input your API Gateway URL as the webhook endpoint, and New Relic will send alert data to it when the policy triggers. This works similarly to Workflows but is less flexible for complex automation.
内容的提问来源于stack exchange,提问作者Jay Prakash

