Skip to content

Commit

Permalink
Merge pull request #12 from cherusk/feature_improve_selection_config
Browse files Browse the repository at this point in the history
feature improve selection config
  • Loading branch information
cherusk authored Jan 6, 2023
2 parents 0160374 + 691027f commit 7a42eac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
15 changes: 7 additions & 8 deletions example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ logic:
#- 1500
#cmds: # flow of which command holding the soccekt
#- "firefox"
#stack:
#peers: # flows that are peering to certain targets
# addresses:
#- "8.8.4.4"
# networks: # in cidr - only IPv4 so far
# - 169.254.0.0/16
# hosts:
#- "some.de"
#peering: # flows that are peering to certain targets
# addresses:
#- "8.8.4.4"
# networks: # in cidr - only IPv4 so far
# - 169.254.0.0/16
# hosts:
#- "some.de"
#portranges: # flows in a certain local port range
#- lower: 2000
#upper: 10000
8 changes: 4 additions & 4 deletions prometheus_ss_exporter/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def arbitrate(self, flow):
return self._core(flow)

def _arbitrate(self, flow):
conditions = [self.discern.ports(flow, self.cnfg['stack']['portranges']),
conditions = [self.discern.ports(flow, self.cnfg['peering']['portranges']),
self.discern.peers(flow,
hosts=self.cnfg['stack']['nodes']['hosts'],
addresses=self.cnfg['stack']['nodes']['addresses'],
networks=self.cnfg['stack']['nodes']['networks']),
hosts=self.cnfg['peering']['nodes']['hosts'],
addresses=self.cnfg['peering']['nodes']['addresses'],
networks=self.cnfg['peering']['nodes']['networks']),
self.discern.process(flow,
pids=self.cnfg['process']['pids'],
cmds=self.cnfg['process']['cmds'])
Expand Down
18 changes: 18 additions & 0 deletions test/selection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def test_peers_decline(self):
flow = {'dst_host': 'test.root.org'}
outcome = SelectorTesting.discerner.peers(flow,
hosts=selector_hosts)

self.assertFalse(outcome)

selector_networks = ["192.168.0.0/16"]
flow = {'dst': '91.189.92.41'}

outcome = SelectorTesting.discerner.peers(flow,
networks=selector_networks)

self.assertFalse(outcome)

def test_peers_accept_test(self):
Expand All @@ -35,6 +44,15 @@ def test_peers_accept_test(self):
flow = {'dst_host': 'test.leave.org'}
outcome = SelectorTesting.discerner.peers(flow,
hosts=selector_hosts)

self.assertTrue(outcome)

selector_networks = ["192.168.0.0/16"]
flow = {'dst': '192.168.1.1'}

outcome = SelectorTesting.discerner.peers(flow,
networks=selector_networks)

self.assertTrue(outcome)

def test_port_decline_test(self):
Expand Down

0 comments on commit 7a42eac

Please sign in to comment.