Browse Source

send fingerprint data when replaying a log file for test reasons

Tobias Begalke 7 years ago
parent
commit
1435b1ce59
3 changed files with 39 additions and 11 deletions
  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
 #!/bin/sh
 
 
+

+ 5 - 6
build-rpm-centos7.sh

@@ -9,6 +9,7 @@ CONFIG_FILE="$BINARY.toml"
 SERVICE_FILE="$BINARY.service"
 SERVICE_FILE="$BINARY.service"
 PKG_TYPE=rpm
 PKG_TYPE=rpm
 DESCR="ScraperWall traffic collector"
 DESCR="ScraperWall traffic collector"
+OUTDIR=./rpms-centos7
 RPM_DIR=/opt/rpm.scraperwall.com/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" \
   --config-files "etc/$BINARY/$CONFIG_FILE" \
   --rpm-trigger-after-install "[]$BINARY: ./after-install-trigger-centos7.sh" \
   --rpm-trigger-after-install "[]$BINARY: ./after-install-trigger-centos7.sh" \
   --rpm-trigger-before-uninstall "[]$BINARY: ./before-uninstall-trigger-centos7.sh" \
   --rpm-trigger-before-uninstall "[]$BINARY: ./before-uninstall-trigger-centos7.sh" \
-  -p rpms-centos7 \
+  -p $OUTDIR \
   --rpm-sign
   --rpm-sign
 
 
 ok=$?
 ok=$?
 
 
 rm -rf $DESTDIR
 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
 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"
   cp "$rpm_file" "$RPM_DIR"
 
 
 	(cd "$RPM_DIR" && \
 	(cd "$RPM_DIR" && \
    createrepo -v . && \
    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
 fi

+ 33 - 5
main.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"log"
 	"log"
+	"math/rand"
 	"net"
 	"net"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
@@ -50,11 +51,12 @@ var (
 	beQuiet   = flag.Bool("quiet", true, "Be quiet")
 	beQuiet   = flag.Bool("quiet", true, "Be quiet")
 	doVersion = flag.Bool("version", false, "Show version information")
 	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 contains the program Version, e.g. 1.0.1
 	Version string
 	Version string
@@ -162,6 +164,11 @@ func main() {
 		log.Fatalf("Encoded Connection: %v!\n", err)
 		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?
 	// What should I do?
 	if config.RequestsFile != "" {
 	if config.RequestsFile != "" {
 		replayFile()
 		replayFile()
@@ -502,6 +509,8 @@ func replayFile() {
 	var startTs time.Time
 	var startTs time.Time
 	var endTs time.Time
 	var endTs time.Time
 
 
+	rand.Seed(time.Now().UnixNano())
+
 	for {
 	for {
 		fh, err := os.Open(config.RequestsFile)
 		fh, err := os.Open(config.RequestsFile)
 		if err != nil {
 		if err != nil {
@@ -536,6 +545,25 @@ func replayFile() {
 
 
 			natsEC.Publish(config.NatsQueue, &req)
 			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++
 			count++
 			if config.SleepFor.Duration >= time.Nanosecond {
 			if config.SleepFor.Duration >= time.Nanosecond {
 				endTs = time.Now()
 				endTs = time.Now()