generated from sergeyWh1te/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from lidofinance/new-finding
feat: support new Finding object
- Loading branch information
Showing
13 changed files
with
283 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Finding", | ||
"type": "object", | ||
"properties": { | ||
"severity": { | ||
"$ref": "#/definitions/Severity" | ||
}, | ||
"alertId": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"uniqueKey": { | ||
"type": "string" | ||
}, | ||
"blockTimestamp": { | ||
"type": "integer" | ||
}, | ||
"blockNumber": { | ||
"type": "integer" | ||
}, | ||
"txHash": { | ||
"type": "string" | ||
}, | ||
"botName": { | ||
"type": "string" | ||
}, | ||
"team": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["severity", "alertId", "name", "description", "botName", "team"], | ||
"definitions": { | ||
"Severity": { | ||
"type": "string", | ||
"enum": ["Unknown", "Info", "Low", "Medium", "High", "Critical"] | ||
} | ||
} | ||
} |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,47 @@ | ||
package notifiler | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/lidofinance/finding-forwarder/generated/databus" | ||
) | ||
|
||
func FormatAlert(alert *databus.FindingDtoJson, source string) string { | ||
var ( | ||
body string | ||
footer string | ||
) | ||
|
||
if len(alert.Description) != 0 { | ||
body = alert.Description | ||
footer += "\n\n" | ||
} | ||
|
||
footer += fmt.Sprintf("Alert Id: %s", alert.AlertId) | ||
footer += fmt.Sprintf("\nBot name: %s", alert.BotName) | ||
footer += fmt.Sprintf("\nTeam: %s", alert.Team) | ||
|
||
if alert.BlockNumber != nil { | ||
footer += fmt.Sprintf("\nBlock number: [%d](https://etherscan.io/block/%d)", *alert.BlockNumber, *alert.BlockNumber) | ||
} | ||
|
||
if alert.TxHash != nil { | ||
footer += fmt.Sprintf("\nTx hash: [%s](https://etherscan.io/tx/%s)", shortenHex(*alert.TxHash), *alert.TxHash) | ||
} | ||
|
||
footer += fmt.Sprintf("\nSource: %s", source) | ||
footer += fmt.Sprintf("\nServer timestamp: %s", time.Now().Format("15:04:05.000 MST")) | ||
if alert.BlockTimestamp != nil { | ||
footer += fmt.Sprintf("\nBlock timestamp: %s", time.Unix(int64(*alert.BlockTimestamp), 0).Format("15:04:05.000 MST")) | ||
} | ||
|
||
return fmt.Sprintf("%s%s", body, footer) | ||
} | ||
|
||
func shortenHex(input string) string { | ||
if len(input) <= 10 { | ||
return input | ||
} | ||
return fmt.Sprintf("x%s...%s", input[2:5], input[len(input)-3:]) | ||
} |
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.