github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/tools/rules/main.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"io/ioutil"
     7  	"os"
     8  
     9  	"github.com/lulzWill/go-agent/internal"
    10  )
    11  
    12  func fail(reason string) {
    13  	fmt.Println(reason)
    14  	os.Exit(1)
    15  }
    16  
    17  func main() {
    18  	if len(os.Args) < 3 {
    19  		fail("improper usage: ./rules path/to/reply_file input")
    20  	}
    21  
    22  	connectReplyFile := os.Args[1]
    23  	name := os.Args[2]
    24  
    25  	data, err := ioutil.ReadFile(connectReplyFile)
    26  	if nil != err {
    27  		fail(fmt.Sprintf("unable to open '%s': %s", connectReplyFile, err))
    28  	}
    29  
    30  	var reply internal.ConnectReply
    31  	err = json.Unmarshal(data, &reply)
    32  	if nil != err {
    33  		fail(fmt.Sprintf("unable unmarshal reply: %s", err))
    34  	}
    35  
    36  	// Metric Rules
    37  	out := reply.MetricRules.Apply(name)
    38  	fmt.Println("metric rules applied:", out)
    39  
    40  	// Url Rules + Txn Name Rules + Segment Term Rules
    41  
    42  	out = internal.CreateFullTxnName(name, &reply, true)
    43  	fmt.Println("treated as web txn name:", out)
    44  
    45  	out = internal.CreateFullTxnName(name, &reply, false)
    46  	fmt.Println("treated as backround txn name:", out)
    47  }