github.com/newrelic/newrelic-client-go@v1.1.0/pkg/nrqldroprules/example_basic_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package nrqldroprules
     5  
     6  import (
     7  	"log"
     8  	"os"
     9  
    10  	"github.com/newrelic/newrelic-client-go/pkg/config"
    11  )
    12  
    13  func Example_basic() {
    14  	// Initialize the client configuration.  A Personal API key is required to
    15  	// communicate with the backend API.
    16  	cfg := config.New()
    17  	cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")
    18  
    19  	// Initialize the client.
    20  	client := New(cfg)
    21  
    22  	accountID := 12345678
    23  
    24  	// List the NRQL drop rules for a given account.
    25  	_, err := client.GetList(accountID)
    26  	if err != nil {
    27  		log.Fatal("error listing NRQL drop rules: ", err)
    28  	}
    29  
    30  	// Create a new events to metrics rule.
    31  	createInput := []NRQLDropRulesCreateDropRuleInput{
    32  		{
    33  			Action:      NRQLDropRulesActionTypes.DROP_DATA,
    34  			Description: "NRQL drop rule description",
    35  			NRQL:        "SELECT * FROM Log WHERE container_name = 'noise'",
    36  		},
    37  	}
    38  
    39  	created, err := client.NRQLDropRulesCreate(accountID, createInput)
    40  	if err != nil {
    41  		log.Fatal("error creating NRQL drop rules: ", err)
    42  	}
    43  
    44  	// Delete an existing events to metrics rule.
    45  	deleteInput := []string{created.Successes[0].ID}
    46  	_, err = client.NRQLDropRulesDelete(accountID, deleteInput)
    47  	if err != nil {
    48  		log.Fatal("error deleting NRQL drop rules: ", err)
    49  	}
    50  }