Skip to content

Instantly share code, notes, and snippets.

@gspncr
Created October 14, 2020 14:44
Show Gist options
  • Save gspncr/533863f837e14fcd56e3f352965b561c to your computer and use it in GitHub Desktop.
Save gspncr/533863f837e14fcd56e3f352965b561c to your computer and use it in GitHub Desktop.
Demo New Relic Data Drop Rules

Drop Application

Replace accountId and of course, test out the rule to match your use case

mutation {
    nrqlDropRulesCreate(accountId: 1147177, rules: [
        {
            action: DROP_DATA
            nrql: "SELECT * FROM TestEvent WHERE appName='NR-One Production'"
            description: "drop data from appName is 'NR-One Production'"
        }
    ])
    {
        successes { id }
        failures {
            submitted { nrql }
            error { reason description }
        }
    }
}

Drop Attributes

Replace accountId and of course, test out the rule to match your use case

mutation {
    nrqlDropRulesCreate(accountId: 1147177, rules: [
        {
            action: DROP_ATTRIBUTES
            nrql: "SELECT user FROM TestEvent"
            description: "Removes datanerd@example.com"
        }
    ])
    {
        successes { id }
        failures {
            submitted { nrql }
            error { reason description }
        }
    }
}

View Drop Rules

Replace accountId

{
    actor {
        account(id: 1147177) {
            nrqlDropRules {
                list {
                    rules {
                        id
                        nrql
                        accountId
                        action
                        createdBy
                        createdAt
                        description
                    }
                    error { reason description } 
                }
            }
        }
    }
}
import requests, time
url = "https://insights-collector.newrelic.com/v1/accounts/<YOUR ACCOUNT ID>/events"
headers = {
'Content-Type': 'application/json',
'X-Insert-Key': '<INSERT KEY>'
}
def staging():
payload = "[\n\t{\n\t\t\"eventType\":\"TestEvent\",\n\t\t\"garySays\": \"hello\",\n\t\t\"message\": \"5pm is so long away\",\n\t\t\"user\": \"datanerd@example.com\",\n \"appName\": \"NR-One Staging\"\n\t}\n]"
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
def production():
payload = "[\n\t{\n\t\t\"eventType\":\"TestEvent\",\n\t\t\"garySays\": \"hello\",\n\t\t\"message\": \"6pm is so long away\",\n\t\t\"user\": \"datanerd@example.com\",\n \"appName\": \"NR-One Production\"\n\t}\n]"
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
def pizza():
payload = "[\n\t{\n\t\t\"eventType\":\"TestEvent\",\n\t\t\"garySays\": \"U+1F355\",\n\t\t\"message\": \"when i WFH\",\n\t\t\"userName\": \"datanerd@example.com\",\n \"appName\": \"spaghettiCodeImpliesMeatballCode\"\n\t}\n]"
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
while True:
staging()
production()
pizza()
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment