Bladeren bron

send fingerprint data when replaying a log file for test reasons

Tobias Begalke 7 jaren geleden
bovenliggende
commit
1435b1ce59
3 gewijzigde bestanden met toevoegingen van 39 en 11 verwijderingen
  1. 1 0
      after-install-trigger-centos7.sh
  2. 5 6
      build-rpm-centos7.sh
  3. 33 5
      main.go

+ 1 - 0
after-install-trigger-centos7.sh

@@ -1,2 +1,3 @@
 #!/bin/sh
 
+

+ 5 - 6
build-rpm-centos7.sh

@@ -9,6 +9,7 @@ CONFIG_FILE="$BINARY.toml"
 SERVICE_FILE="$BINARY.service"
 PKG_TYPE=rpm
 DESCR="ScraperWall traffic collector"
+OUTDIR=./rpms-centos7
 RPM_DIR=/opt/rpm.scraperwall.com/centos7
 
 
@@ -33,21 +34,19 @@ fpm -s dir -t $PKG_TYPE -C $DESTDIR --name $BINARY \
   --config-files "etc/$BINARY/$CONFIG_FILE" \
   --rpm-trigger-after-install "[]$BINARY: ./after-install-trigger-centos7.sh" \
   --rpm-trigger-before-uninstall "[]$BINARY: ./before-uninstall-trigger-centos7.sh" \
-  -p rpms-centos7 \
+  -p $OUTDIR \
   --rpm-sign
 
 ok=$?
 
 rm -rf $DESTDIR
 
-exit
-
-rpm_file="$BINARY-$VERSION-$ITERATION.x86_64.rpm"
+rpm_file="$OUTDIR/$BINARY-$VERSION-$ITERATION.x86_64.rpm"
 if [ $ok -eq 0 -a -f "$rpm_file" ]; then
-	rm -f "$RPM_DIR/$BINARY-*.rpm"
+	# rm -f "$RPM_DIR/$BINARY-*.rpm"
   cp "$rpm_file" "$RPM_DIR"
 
 	(cd "$RPM_DIR" && \
    createrepo -v . && \
-   rsync -av --progress --delete . fender.spyz.org:/srv/http-vhosts/rpm.scraperwall.com/)
+   rsync -av --progress --delete . fender.spyz.org:/srv/http-vhosts/rpm.scraperwall.com/centos7/)
 fi

+ 33 - 5
main.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"io"
 	"log"
+	"math/rand"
 	"net"
 	"net/http"
 	"os"
@@ -50,11 +51,12 @@ var (
 	beQuiet   = flag.Bool("quiet", true, "Be quiet")
 	doVersion = flag.Bool("version", false, "Show version information")
 
-	natsEC  *nats.EncodedConn
-	count   uint64
-	timeout = -1 * time.Second
-	ipPriv  *ip.IP
-	config  Config
+	natsEC     *nats.EncodedConn
+	natsJsonEC *nats.EncodedConn
+	count      uint64
+	timeout    = -1 * time.Second
+	ipPriv     *ip.IP
+	config     Config
 
 	// Version contains the program Version, e.g. 1.0.1
 	Version string
@@ -162,6 +164,11 @@ func main() {
 		log.Fatalf("Encoded Connection: %v!\n", err)
 	}
 
+	natsJsonEC, err = nats.NewEncodedConn(natsConn, nats.JSON_ENCODER)
+	if err != nil {
+		log.Fatalf("Encoded Connection: %v!\n", err)
+	}
+
 	// What should I do?
 	if config.RequestsFile != "" {
 		replayFile()
@@ -502,6 +509,8 @@ func replayFile() {
 	var startTs time.Time
 	var endTs time.Time
 
+	rand.Seed(time.Now().UnixNano())
+
 	for {
 		fh, err := os.Open(config.RequestsFile)
 		if err != nil {
@@ -536,6 +545,25 @@ func replayFile() {
 
 			natsEC.Publish(config.NatsQueue, &req)
 
+			if strings.Index(r[1], ".") < 0 {
+				fp := data.Fingerprint{
+					ClientID:    "scw",
+					Fingerprint: fmt.Sprintf("%x%x%x%x\n", rand.Int(), rand.Int(), rand.Int(), rand.Int()),
+					Remote:      r[0],
+					Url:         r[1],
+					Source:      r[0],
+					CreatedAt:   time.Now(),
+				}
+
+				if strings.HasPrefix(r[0], "50.31.") {
+					fp.Fingerprint = "a1f2c2ee560ce6580d66d451a9c8dfbf"
+					natsJsonEC.Publish("fingerprints_scw", fp)
+				} else if rand.Intn(10) < 8 {
+					natsJsonEC.Publish("fingerprints_scw", fp)
+				}
+
+			}
+
 			count++
 			if config.SleepFor.Duration >= time.Nanosecond {
 				endTs = time.Now()