Skip to content

Commit

Permalink
Add notification settings management
Browse files Browse the repository at this point in the history
  • Loading branch information
PENEKhun committed Sep 29, 2024
1 parent 56b6e07 commit 27a6cc9
Show file tree
Hide file tree
Showing 48 changed files with 2,253 additions and 1,283 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ out/
### SpringDog ###
derby.log
springdog-embedded-database
springdog-settings.json
64 changes: 3 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,18 @@ video.

The system sends email notifications in the following scenarios:

1. When the [pre-defined](#springdogsystem-watch) system usage threshold is exceeded or returns to
1. When the pre-defined system usage threshold is exceeded or returns to
normal
<img src="https://github.com/user-attachments/assets/e9d575d3-bda9-4ade-b1e5-5a09eee0bded" width="50%">

2. When the response time of a [pre-defined](#springdogslow-response) endpoint exceeds the specified
2. When the response time of a pre-defined endpoint exceeds the specified
threshold
<img src="https://github.com/user-attachments/assets/58f59637-9693-4ebf-9e01-b1768b0b2ba8" width="30%">

These notification features allow system administrators to quickly identify and respond to potential
issues.

## Options

For minor configurations, you can use the following options in your application properties. For more
detailed or advanced configurations that are not available here, you can access the Springdog agent
directly.

> ⚠️ Note: To receive notifications for [system-watch](#springdogsystem-watch)
> and [slow-response](#springdogslow-response) features, the gmail
> notification option must be enabled.
## Properties

```yaml
springdog:
Expand All @@ -91,20 +83,6 @@ springdog:
username: admin
password: admin
externalAccess: false
notification:
gmail:
enabled: false
recipient:
username:
password:
system-watch:
enabled: false
cpuThreshold: 80 # percentage
memoryThreshold: 80 # percentage
diskThreshold: 80 # percentage
slow-response:
enabled: false
threshold: 1000 # ms
```
### springdog.agent
Expand All @@ -118,42 +96,6 @@ springdog:
| password | x | The password for the Springdog agent. Empty fields are not allowed. | admin |
| externalAccess | x | Whether to allow external access to the Springdog agent. If `false`, access from external IPs is not allowed. | false | `true` or `false` |

### springdog.notification.gmail

> [system-watch](#springdogsystem-watch), [slow-response](#springdogslow-response) notifications are
> sent via Gmail.

| Name | Required | Description | Default | Value Sets |
|-----------|------------|-----------------------------------------------------------------------------------------------------------------------------------|---------|-------------------------------|
| enabled | x | Whether to enable Gmail notifications. | false | `true` or `false` |
| recipient | △(enabled) | The recipient's email address. | | Must be a valid email address |
| username | △(enabled) | The Gmail username. | |
| password | △(enabled) | The Gmail App password. details in [here](https://support.google.com/mail/thread/205453566/how-to-generate-an-app-password?hl=en) | |

### springdog.system-watch

> Monitor the system's CPU, memory, and disk usage.
> If the usage exceeds the threshold, a notification will be sent.
>
> ⚠️ Threshold `0` means that is disabled.

| Name | Required | Description | Default | Value Sets |
|-----------------|------------|--------------------------------------------------------------------------------------------------|---------|--------------------|
| enabled | x | Whether to enable system watch. | false | `true` or `false` |
| cpuThreshold | △(enabled) | The CPU usage threshold. If the CPU usage exceeds this value, a notification will be sent. | 0.0 | `0.0 < x <= 100.0` |
| memoryThreshold | △(enabled) | The memory usage threshold. If the memory usage exceeds this value, a notification will be sent. | 0.0 | `0.0 < x <= 100.0` |
| diskThreshold | △(enabled) | The disk usage threshold. If the disk usage exceeds this value, a notification will be sent. | 0.0 | `0.0 < x <= 100.0` |

### springdog.slow-response

> For all endpoints, send a notification if the response time is slower than a specified number of
*milliseconds*.

| Name | Required | Description | Default | Value Sets |
|-------------|------------|----------------------------------------------------------------------------------------------------|---------|-------------------|
| enabled | x | Whether to enable slow response. | false | `true` or `false` |
| thresholdMs | △(enabled) | The slow response threshold. If the response time exceeds this value, a notification will be sent. | 0 | `0 < x` (ms) |

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ flywayVersion=10.17.1
classgraphVersion=4.8.175
seleniumVersion=4.24.0
webdrivermanagerVersion=5.9.2
jacksonVersion=2.17.2
# For deploy to maven central
SONATYPE_HOST=CENTRAL_PORTAL
SONATYPE_CONNECT_TIMEOUT_SECONDS=300
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import org.easypeelsecurity.springdog.shared.configuration.SpringdogProperties;
import org.easypeelsecurity.springdog.shared.dto.EndpointDto;
import org.easypeelsecurity.springdog.shared.dto.ErrorTracingDto;
import org.easypeelsecurity.springdog.shared.settings.NotificationGlobalSetting;
import org.easypeelsecurity.springdog.shared.settings.SlowResponseSetting;
import org.easypeelsecurity.springdog.shared.settings.SpringdogSettingManagerImpl;
import org.easypeelsecurity.springdog.shared.settings.SystemWatchSetting;
import org.easypeelsecurity.springdog.shared.util.Assert;

/**
Expand All @@ -58,6 +62,8 @@ public class SpringdogAgentView {
private ExceptionListingService exceptionListingService;
@Autowired
private SpringdogProperties properties;
@Autowired
private SpringdogSettingManagerImpl settingManager;

@GetMapping("/login")
public String login() {
Expand Down Expand Up @@ -135,6 +141,72 @@ public String modifyRateLimit(@PathVariable(name = "endpointId") long endpointId
return viewRateLimitSpecific(endpointId, model);
}

@GetMapping("/notification")
public String notificationSettingView(Model model) {
model.addAttribute("mailConfiguration", settingManager.getSettings().getNotificationGlobalSetting());
return "/templates/content/notification/configuration.html";
}

@PostMapping("/notification")
public String notificationSettingUpdate(Model model, @ModelAttribute("mailConfiguration")
NotificationGlobalSetting newSetting) {
try {
settingManager.updateNotificationGlobalSetting(newSetting);
} catch (Exception e) {
model.addAttribute("result", false);
model.addAttribute("message", e.getMessage());
return notificationSettingView(model);
}

model.addAttribute("result", true);
model.addAttribute("message", "Successfully updated");
return notificationSettingView(model);
}

@GetMapping("/notification/system-watch")
public String notificationSystemWatchView(Model model) {
model.addAttribute("systemWatchConfiguration", settingManager.getSettings().getSystemWatchSetting());
return "/templates/content/notification/system-watch.html";
}

@PostMapping("/notification/system-watch")
public String notificationSystemWatchSettingUpdate(Model model, @ModelAttribute("systemWatchConfiguration")
SystemWatchSetting newSetting) {
try {
settingManager.updateSystemWatchSetting(newSetting);
} catch (Exception e) {
model.addAttribute("result", false);
model.addAttribute("message", e.getMessage());
return notificationSystemWatchView(model);
}

model.addAttribute("result", true);
model.addAttribute("message", "Successfully updated");
return notificationSystemWatchView(model);
}

@GetMapping("/notification/slow-response")
public String notificationSlowResponseView(Model model) {
model.addAttribute("slowResponseConfiguration", settingManager.getSettings().getSlowResponseSetting());
return "/templates/content/notification/slow-response.html";
}

@PostMapping("/notification/slow-response")
public String notificationSlowResponseSettingUpdate(Model model, @ModelAttribute("slowResponseConfiguration")
SlowResponseSetting newSetting) {
try {
settingManager.updateSlowResponseSetting(newSetting);
} catch (Exception e) {
model.addAttribute("result", false);
model.addAttribute("message", e.getMessage());
return notificationSlowResponseView(model);
}

model.addAttribute("result", true);
model.addAttribute("message", "Successfully updated");
return notificationSlowResponseView(model);
}

@GetMapping("/error-tracing")
public String errorTracingHome(Model model) {
List<ErrorTracingDto> causes = exceptionListingService.getAllParentCauses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3216,14 +3216,14 @@ textarea.form-control-lg {

.btn-primary {
color: #fff;
background-color: #0d6efd;
border-color: #0d6efd;
background-color: #3b765c;
border-color: #3b765c;
}

.btn-primary:hover {
color: #fff;
background-color: #0b5ed7;
border-color: #0a58ca;
background-color: #4abf8c;
border-color: #4abf8c;
}

.btn-check:focus + .btn-primary, .btn-primary:focus {
Expand Down Expand Up @@ -4266,7 +4266,7 @@ textarea.form-control-lg {
.nav-link {
display: block;
padding: 0.5rem 1rem;
color: #0d6efd;
color: #5883c2;
text-decoration: none;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}
Expand Down Expand Up @@ -4332,7 +4332,7 @@ textarea.form-control-lg {
.nav-pills .nav-link.active,
.nav-pills .show > .nav-link {
color: #fff;
background-color: #0d6efd;
background-color: #364862;
}

.nav-fill > .nav-link,
Expand Down Expand Up @@ -4941,7 +4941,8 @@ textarea.form-control-lg {
background-color: #fff;
background-clip: border-box;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: 0.25rem;
margin-bottom: 1rem;
border-radius: 1rem;
}

.card > hr {
Expand Down Expand Up @@ -4977,6 +4978,7 @@ textarea.form-control-lg {
}

.card-title {
font-size: 1rem;
margin-bottom: 0.5rem;
}

Expand All @@ -4985,6 +4987,10 @@ textarea.form-control-lg {
margin-bottom: 0;
}

.card-text {
font-size: 0.9rem;
}

.card-text:last-child {
margin-bottom: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@
}
}

.card {
margin-bottom: 1rem;
}

.card-title {
font-size: 1rem;
}

.card-text {
font-size: 0.9rem;
}

.table th, .table td {
vertical-align: middle;
}
Expand Down
Loading

0 comments on commit 27a6cc9

Please sign in to comment.