コード例 #1
0
ファイル: sqrt_trigger.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize("/etc/GTSOA/soa.conf")

	var wg sync.WaitGroup

	for j := 0; j < 1; j++ {
		wg.Add(1)
		go func() {
			client, err := scamp.Dial("0.0.0.0:63531")
			if err != nil {
				scamp.Error.Printf("could not dial service: `%s`", err)
				return
			}

			for i := 0; i < 1; i++ {
				reqId := i + 1
				wg.Add(1)
				go func() {
					msg := scamp.NewRequestMessage()
					msg.SetAction("verify")
					msg.SetRequestId(reqId)
					scamp.Info.Printf("reqId: %d", reqId)

					var req SqrtRequest
					req.Input = rand.NormFloat64()

					expSqrt := math.Sqrt(req.Input)

					var expResp SqrtResponse
					if math.IsNaN(expSqrt) {
						expResp.NaN = true
					} else {
						expResp.Output = expSqrt
					}
					expBytes, err := json.Marshal(expResp)
					if err != nil {
						scamp.Info.Printf("could not marshal exp resp: `%s`", err)
						return
					}

					msg.WriteJson(req)
					respChan, err := client.Send(msg)
					if err != nil {
						scamp.Error.Printf("could not send message: `%s`", err)
					}
					resp := <-respChan
					if !bytes.HasPrefix(resp.Bytes(), expBytes) {
						scamp.Error.Printf("response did not match: got `%s`, expected `%s`", string(resp.Bytes()), string(expBytes))
						os.Exit(1)
					}
					// scamp.Info.Printf("resp: %s", resp.Bytes())
					wg.Done()
				}()
			}
			wg.Done()
		}()
	}

	wg.Wait()
}
コード例 #2
0
ファイル: sqrt_service.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize("/etc/GTSOA/soa.conf")

	svc, err := scamp.NewService("0.0.0.0:63531", "service_verifier")
	if err != nil {
		scamp.Error.Printf("could not create service: `%s`", err.Error())
		os.Exit(1)
	}

	var reqCnt uint64 = 0
	go func() {
		for {
			reqLcl := atomic.LoadUint64(&reqCnt)
			scamp.Info.Printf("cnt: %d", reqLcl)
			time.Sleep(time.Duration(10) * time.Second)
		}
	}()

	// svc.Register("sqrt", func(msg *scamp.Message, client *scamp.Client) {
	//   atomic.AddUint64(&reqCnt,1)
	//   var sqrtReq SqrtRequest
	//   err = json.NewDecoder(bytes.NewReader(msg.Bytes())).Decode(&sqrtReq)
	//   if err != nil {
	//     scamp.Error.Printf("nooo: `%s`", err)
	//     return
	//   }

	//   // scamp.Info.Printf("sqrt req: %s", sqrtReq)

	//   var sqrtResp SqrtResponse

	//   res := math.Sqrt(sqrtReq.Input)
	//   if math.IsNaN(res) {
	//     sqrtResp.NaN = true
	//   } else {
	//     sqrtResp.Output = res
	//   }

	//   var buf bytes.Buffer
	//   err = json.NewEncoder(&buf).Encode(sqrtResp)
	//   if err != nil {
	//     scamp.Error.Printf("nooo: `%s`", err)
	//     return
	//   }

	//   resp := scamp.NewResponseMessage()
	//   resp.SetRequestId(msg.RequestId)
	//   resp.Write(buf.Bytes())
	//   _,err = client.Send(resp)
	//   if err != nil {
	//     panic(err.Error())
	//   }
	// })

	svc.Run()
}
コード例 #3
0
ファイル: watchdog.go プロジェクト: gudTECH/scamp-go
func main() {
	var err error
	var ok bool

	gtConfigPathPtr := flag.String("config", "/backplane/discovery/discovery", "path to the discovery file")
	discoveryPathOverride := flag.String("discovery-path", "", "override configured discovery path (useful for testing)")
	inventoryPath := flag.String("expected-inventory", "", "config file specifying which actions and in what quantity are expected")
	scanWaitPtr := flag.Int("wait", 10, "how long to wait between action scans")
	pagerdutyKeyPtr := flag.String("pagerduty-key-path", "/etc/PagerDutyServiceKey", "location of the api key for pagerduty")
	modePtr := flag.String("mode", "watch", "one of 'watch' or 'dump-inventory'")
	flag.Parse()

	err = scamp.Initialize(*gtConfigPathPtr)
	if err != nil {
		fmt.Printf("could not initialize scamp: `%s`\n", err)
		return
	}

	if *inventoryPath == "" {
		fmt.Printf("must provide expected-inventory path")
		return
	}

	var discoveryPath string
	if *discoveryPathOverride != "" {
		discoveryPath = *discoveryPathOverride
	} else {
		discoveryPath, ok = scamp.DefaultConfig().Get("discovery.cache_path")
		if !ok {
			fmt.Printf("config is missing `discovery.cache_path`\n")
			return
		}
	}

	if *modePtr == "watch" {
		err = doWatch(*inventoryPath, discoveryPath, *scanWaitPtr, *pagerdutyKeyPtr)
	} else if *modePtr == "dump-inventory" {
		err = doDump(*inventoryPath, discoveryPath)
		if err != nil {
			fmt.Println("failed to dump inventory:", err.Error())
			os.Exit(1)
		}

		fmt.Println("data successfully written")

	} else {
		fmt.Println("unsupported mode ", *modePtr)
		os.Exit(1)
	}

	if err != nil {
		scamp.Error.Printf("failed: `%s`", err)
	}
}
コード例 #4
0
ファイル: scamp_service.go プロジェクト: gudTECH/heka-scamp
func (sip *SCAMPInputPlugin) Init(config interface{}) (err error) {
	scamp.Initialize(scamp.DefaultConfigPath)
	sip.conf = config.(*SCAMPInputPluginConfig)

	if len(sip.conf.Handlers) < 1 {
		err = errors.New("must provide at least 1 handler")
		return
	}

	return
}
コード例 #5
0
ファイル: scamp_requester.go プロジェクト: gudTECH/heka-scamp
func (sop *SCAMPOutputPlugin) Init(config interface{}) (err error) {
	scamp.Initialize(scamp.DefaultConfigPath)

	sop.conf = config.(*SCAMPOutputPluginConfig)

	scamp.Info.Printf("Connecting to %s\n", sop.conf.Service)
	sop.client, err = scamp.Dial(sop.conf.Service)
	if err != nil {
		return
	}

	return
}
コード例 #6
0
ファイル: scamp.go プロジェクト: dnorman/scamp-go
func main() {
	scamp.Initialize()

	flag.StringVar(&announcePath, "announcepath", "", "payload to be signed")
	flag.StringVar(&certPath, "certpath", "", "path to cert used for signing")
	flag.StringVar(&keyPath, "keypath", "", "path to service private key")
	flag.Parse()

	if len(keyPath) == 0 || len(announcePath) == 0 || len(certPath) == 0 {
		fmt.Println("must provide all 3: certpath, keypath, and announcepath")
		return
	}

	keyRawBytes, err := ioutil.ReadFile(keyPath)
	if err != nil {
		scamp.Error.Fatalf("could not read key at %s", keyPath)
	}

	block, _ := pem.Decode(keyRawBytes)

	if block == nil {
		scamp.Error.Fatalf("could not decode key data (%s)", block.Type)
		return
	} else if block.Type != "RSA PRIVATE KEY" {
		scamp.Error.Fatalf("expected key type 'RSA PRIVATE KEY' but got '%s'", block.Type)
	}

	privKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
	if err != nil {
		scamp.Error.Fatalf("could not parse key from %s (%s)", keyPath, block.Type)
	}

	announceData, err := ioutil.ReadFile(announcePath)
	if err != nil {
		scamp.Error.Fatalf("could not read announce data from %s", announcePath)
	}
	announceSig, err := scamp.SignSHA256([]byte(announceData), privKey)
	if err != nil {
		scamp.Error.Fatalf("could not sign announce data: %s", err)
	}

	certData, err := ioutil.ReadFile(certPath)
	if err != nil {
		scamp.Error.Fatalf("could not read cert from %s", certPath)
	}

	fmt.Printf("\n%%%%%%\n%s\n%s\n%s", announceData, certData, announceSig)

	scamp.Trace.Printf("cool announceSig: %s", announceSig)
}
コード例 #7
0
ファイル: announce.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize("/etc/SCAMP/soa.conf")
	var err error

	multicastPacketConn, err := scamp.LocalMulticastPacketConn()
	if err != nil {
		scamp.Error.Printf("could not create local multicast packet connection")
		return
	}

	for {
		if _, err := multicastPacketConn.WriteTo([]byte("hello, world\n"), nil, scampAnnounceDest); err != nil {
			scamp.Trace.Printf("failed to write to multicast group: `%s`", err)
			break
		}
		scamp.Trace.Printf("wrote hello world to group `%s`", scampAnnounceDest)
		time.Sleep(5 * time.Second)
	}
}
コード例 #8
0
ファイル: service.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize()

	service, err := scamp.NewService(":30100", "helloworld")
	if err != nil {
		scamp.Error.Fatalf("error creating new service: `%s`", err)
	}
	service.Register("helloworld.hello", func(message *scamp.Message, client *scamp.Client) {
		scamp.Info.Printf("go message: `%s`", message.Bytes())
		blob := message.Bytes()

		if len(blob) > 0 {
			scamp.Info.Printf("helloworld had data: %s", blob)
		} else {
			scamp.Trace.Printf("helloworld was called without data")
		}

		reply := &scamp.Message{MessageType: scamp.MESSAGE_TYPE_REPLY}
		reply.Write(famous_words)
		reply.SetRequestId(message.RequestId)
		_, err := client.Send(reply)
		if err != nil {
			scamp.Error.Printf("error while sending reply: `%s`. continuing.", err)
			return
		}
	})

	announcer, err := scamp.NewDiscoveryAnnouncer()
	if err != nil {
		scamp.Error.Printf("failed to create announcer: `%s`", err)
		return
	}
	announcer.Track(service)

	go announcer.AnnounceLoop()

	service.Run()
}
コード例 #9
0
ファイル: pipeline.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize()

	conn, err := scamp.Connect("127.0.0.1:30101")
	defer conn.Close()

	if err != nil {
		scamp.Error.Fatalf("could not connect! `%s`\n", err)
	}

	var sess *scamp.Session

	inflight := make(chan bool, 500)

	for {
		inflight <- true

		go func() {
			sess, err = conn.Send(scamp.Request{
				Action:         "helloworld.hello",
				EnvelopeFormat: scamp.ENVELOPE_JSON,
				Version:        1,
			})
			if err != nil {
				scamp.Error.Fatalf("error initiating session: `%s`", err)
			}

			reply, err := sess.RecvReply()
			if err != nil {
				scamp.Error.Fatalf("error receiving: `%s`", err)
			}
			scamp.Info.Printf("Got reply! `%s`", reply.Blob)

			<-inflight
		}()
	}
}
コード例 #10
0
ファイル: stress_logsink.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize()

	var clients []*scamp.Client = make([]*scamp.Client, 10000)

	var wg sync.WaitGroup

	for i := range clients {
		client, err := scamp.Dial("127.0.0.1:30100")
		if err != nil {
			scamp.Error.Fatalf("could not connect! `%s`\n", err)
			return
		}

		clients[i] = client

		wg.Add(1)
		go hitService(client, wg)
	}

	scamp.Info.Printf("waiting for stress to finish")
	wg.Wait()
	scamp.Info.Printf("done with stress")
}
コード例 #11
0
ファイル: scamp.go プロジェクト: gudTECH/scamp-go
func main() {
	gtConfigPathPtr := flag.String("config", "/backplane/discovery/discovery", "path to the discovery file")

	flag.StringVar(&announcePath, "announcepath", "", "payload to be signed")
	flag.StringVar(&certPath, "certpath", "", "path to cert used for signing")
	flag.StringVar(&keyPath, "keypath", "", "path to service private key")
	flag.StringVar(&fingerprintPath, "fingerprintpath", "", "path to cert to fingerprint")
	flag.Parse()

	scamp.Initialize(*gtConfigPathPtr)

	if (len(keyPath) == 0 || len(announcePath) == 0 || len(certPath) == 0) && (len(fingerprintPath) == 0) {
		fmt.Printf("fingerprintpath: %s", fingerprintPath)
		fmt.Println("not enough options specified\nmust provide\n\tcertpath, keypath, and announcepath\nOR\n\tfingerprintpath")
		return
	}

	if len(keyPath) != 0 {
		doFakeDiscoveryCache()
	} else {
		doCertFingerprint()
	}

}
コード例 #12
0
ファイル: dump_config.go プロジェクト: gudTECH/scamp-go
func main() {
	scamp.Initialize("/etc/SCAMP/soa.conf")
	scamp.NewConfig()
}
コード例 #13
0
ファイル: inventory_test.go プロジェクト: gudTECH/scamp-go
func TestMain(m *testing.M) {
	flag.Parse()
	scamp.Initialize("/etc/SCAMP/soa.conf")
	os.Exit(m.Run())
}