Skip to content

Commit

Permalink
Don't create progress bar if there are no fqdns to update (#700)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan L <logan@bhis.co>
  • Loading branch information
Zalgo2462 and Logan L authored Aug 26, 2021
1 parent 031cea0 commit 4a4b639
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions pkg/beaconfqdn/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,43 +147,47 @@ func (r *repo) Upsert(hostMap map[string]*host.Input, minTimestamp, maxTimestamp
s.Stop()
fmt.Println()

// progress bar for troubleshooting
p := mpb.New(mpb.WithWidth(20))
bar := p.AddBar(int64(len(affectedHostnames)),
mpb.PrependDecorators(
decor.Name("\t[-] FQDN Beacon Analysis:", decor.WC{W: 30, C: decor.DidentRight}),
decor.CountersNoUnit(" %d / %d ", decor.WCSyncWidth),
),
mpb.AppendDecorators(decor.Percentage()),
)

// loop over map entries (each hostname)
for _, entry := range affectedHostnames {

// check to make sure hostname has resolved ips, skip otherwise
if len(entry.ResolvedIPs) > 0 {

var dstList []bson.M
for _, dst := range entry.ResolvedIPs {
dstList = append(dstList, dst.AsDst().BSONKey())
if len(affectedHostnames) > 0 {
// progress bar for troubleshooting
p := mpb.New(mpb.WithWidth(20))
bar := p.AddBar(int64(len(affectedHostnames)),
mpb.PrependDecorators(
decor.Name("\t[-] FQDN Beacon Analysis:", decor.WC{W: 30, C: decor.DidentRight}),
decor.CountersNoUnit(" %d / %d ", decor.WCSyncWidth),
),
mpb.AppendDecorators(decor.Percentage()),
)

// loop over map entries (each hostname)
for _, entry := range affectedHostnames {

// check to make sure hostname has resolved ips, skip otherwise
if len(entry.ResolvedIPs) > 0 {

var dstList []bson.M
for _, dst := range entry.ResolvedIPs {
dstList = append(dstList, dst.AsDst().BSONKey())
}

input := &fqdnInput{
FQDN: entry.Host,
DstBSONList: dstList,
ResolvedIPs: entry.ResolvedIPs,
}

dissectorWorker.collect(input)
}

input := &fqdnInput{
FQDN: entry.Host,
DstBSONList: dstList,
ResolvedIPs: entry.ResolvedIPs,
}
// progress bar increment
bar.IncrBy(1)

dissectorWorker.collect(input)
}

// progress bar increment
bar.IncrBy(1)

p.Wait()
} else {
fmt.Println("\t[!] No FQDN Beacon data to analyze")
}

p.Wait()

// start the closing cascade (this will also close the other channels)
dissectorWorker.close()
}
Expand Down

0 comments on commit 4a4b639

Please sign in to comment.