-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: add rwmutex * fix: global ipdb * fix: pass wg to transforms * docs: comment on closure * feat: add ignore_close * refactor: globals, options * docs: ipdb * fix: undo breakage * fix: undo breakage * Update examples/process/ip_lookup/main.go Co-authored-by: Daniel Stinson-Diess <[email protected]> Co-authored-by: Daniel Stinson-Diess <[email protected]>
- Loading branch information
1 parent
2c9e524
commit f799a6f
Showing
13 changed files
with
240 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local ipdb = import '../../../build/config/ip_database.libsonnet'; | ||
local process = import '../../../build/config/process.libsonnet'; | ||
|
||
// the MaxMind City database can be read from local disk, HTTP(S) URL, or AWS S3 URL | ||
// other databases / providers can be used by changing the imported function (e.g., ipdb.maxmind_asn) | ||
local mm_city = ipdb.maxmind_city('location://path/to/maxmind.mmdb'); | ||
|
||
// applies the IPDatabase processor using a MaxMind City database | ||
process.ip_database(input='addr', output='geo', database_options=mm_city) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"addr":"8.8.8.8"} | ||
{"addr":"9.9.9.9"} | ||
{"addr":"208.67.222.222"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// example of reading JSON from a file and applying the IPDatabase processor | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/brexhq/substation/config" | ||
"github.com/brexhq/substation/process" | ||
) | ||
|
||
func main() { | ||
// read lines from data file into encapsulated data | ||
open, err := os.Open("./data.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var capsules []config.Capsule | ||
capsule := config.NewCapsule() | ||
|
||
scanner := bufio.NewScanner(open) | ||
for scanner.Scan() { | ||
capsule.SetData(scanner.Bytes()) | ||
capsules = append(capsules, capsule) | ||
} | ||
|
||
// read config file and create a new batch processor | ||
cfg, err := os.ReadFile("./config.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var sub config.Config | ||
if err := json.Unmarshal(cfg, &sub); err != nil { | ||
panic(err) | ||
} | ||
|
||
proc, err := process.BatchApplicatorFactory(sub) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer proc.Close(context.TODO()) | ||
|
||
// apply batch processor to encapsulated data | ||
capsules, err = process.ApplyBatch(context.TODO(), capsules, proc) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, capsule := range capsules { | ||
fmt.Println(string(capsule.Data())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.