-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed directory name and files #14
Open
mbierman
wants to merge
6
commits into
firewalla:main
Choose a base branch
from
mbierman:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2014a3e
Contribution
mbierman e0a037b
removed token & renamed directory
mbierman 288e3cf
Create export-filtered-flows
mbierman 7d3aad4
removed token & renamed directory
mbierman 274d2b4
Merge branch 'main' of https://github.com/mbierman/msp-api-examples
mbierman 6beba24
Fixed
mbierman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### Story | ||
TBD | ||
|
||
|
||
### Quick Start | ||
|
||
Assume you've already cloned `https://github.com/firewalla/msp-api-examples.git` and `cd export-Filtered-flows` | ||
|
||
```bash | ||
cd flow-pagination | ||
npm install | ||
domain="<YOUR-MSP-DOMAIN>" token="<YOUR-MSP-TOKEN>" node ./index.js | ||
|
||
``` | ||
|
||
### Dependencies | ||
- [Node.js](https://nodejs.org/) | ||
- [npm](https://www.npmjs.com/package/npm), [pnpm](https://pnpm.io/installation), or the package manager you prefer | ||
|
||
Contributor: [@mbierman](https://github.com/mbierman) |
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,22 @@ | ||
const axios = require('axios'); | ||
|
||
// Change these three configurations to what you need | ||
const msp_domain = process.env.msp_domain || "my_mnsp.firewalla.net"; | ||
const token = process.env.token || "my_token"; | ||
const block = process.env.block || "1"; | ||
const limit = process.env.limit || "10"; | ||
const begin = process.env.begin || Date.now() / 1000 - 24 * 3600 | ||
const end = process.env.end || Date.now() / 1000 | ||
|
||
|
||
axios({ | ||
method: 'get', | ||
url: `https://${msp_domain}/v2/flows?begin=${begin}&end=${end}&block=${block}&limit=${limit}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
headers: { | ||
Authorization: `Token ${token}`, | ||
"Content-Type": "application/json" | ||
} | ||
}).then((res) => { | ||
let data = res.data; | ||
console.log(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const axios = require('axios'); | ||
// Output is CSV to console | ||
|
||
// Change these three configurations to what you need | ||
// set to your MSP domain | ||
const msp_domain = process.env.msp_domain || "my_msp.firewalla.net"; | ||
|
||
// replace with your MSP token | ||
const token = process.env.token || "my_token"; | ||
|
||
// block: 1 means blocked flows 0 = unblocked flows | ||
const block = process.env.block || "0"; | ||
|
||
// default to within the last 24 hours | ||
const begin = process.env.begin || Date.now() / 1000 - 24 * 3600; | ||
|
||
// You could also do within the last hour | ||
// const begin = process.env.begin || Math.floor(Date.now() / 1000) - 3600; | ||
// end as of "now" | ||
const end = process.env.end || Date.now() / 1000; | ||
|
||
// this sets max responses | ||
const limit = process.env.limit || 100; | ||
|
||
// replace with the GID of a particular firewalla. | ||
const gid = process.env.gid || "GID"; | ||
|
||
|
||
// In this example, we are going to get up to 10 unblocked flows within the last 24 hours from a specific box: | ||
// and output the | ||
// * date stamp | ||
// * remote IP | ||
// * and remote Domain | ||
|
||
axios({ | ||
method: 'get', | ||
url: `https://${msp_domain}/v2/flows?begin=${begin}&end=${end}&block=${block}&limit=${limit}&gid=${gid}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
headers: { | ||
Authorization: `Token ${token}`, | ||
"Content-Type": "application/json" | ||
} | ||
}).then((res) => { | ||
let data = res.data; | ||
if (data.results && data.results.length > 0) { | ||
const result = data.results[0]; | ||
const ts = result.ts; | ||
const deviceName = result.device.name; | ||
const remoteIP = result.remote.ip; | ||
const remoteDomain = result.remote.domain || ""; | ||
|
||
const csvData = `${ts},${deviceName},${remoteIP},${remoteDomain}`; | ||
console.log(csvData); | ||
} else { | ||
console.log("No data found."); | ||
} | ||
}).catch((err) => { | ||
console.error("Error fetching data:", err.message); | ||
}); | ||
|
||
// sample output | ||
// % node ./flow-export_csv.js | ||
// 1693266677.467,Pigpen / Synology NAS 🗄,192.241.187.136,api.openweathermap.org |
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"axios": "^1.4.0" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export-filtered-flows