Skip to content

Commit

Permalink
Typos etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuaitk committed Sep 30, 2024
1 parent 1b5e45c commit a9c2897
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 48 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ See [keep a changelog] for information about writing changes to this log.

## [1.0.0-beta1] - 2024-09-23

- Added support for silencing alter using metadata on device and tags on gateways.
- Added support for silencing alert using metadata on device and tags on gateways.
- Added logging to check command.
- Added SMS templates and service to alters
- Added SMS templates and service to alerts
- Added application last-seen checker.
- Added device last-seen checker.
- Added Gateway last-seen checker.
Expand Down
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IoT Alter Manager
# IoT Alert Manager

This is a Symfony command-line tool that can be used to set up alerts (sending
both emails and text messages) based on the last time a specific gateway or
Expand Down Expand Up @@ -47,8 +47,7 @@ this path can be reconfigured if needed.
## Logs

The application outputs basic log information and errors to standard output and
error. These logs can be sent to [Loki](https://grafana.com/oss/loki/) when
f.eks. running Docker.
error. These logs can be sent to [Loki](https://grafana.com/oss/loki/) when running e.g. Docker.

## Configurations

Expand Down Expand Up @@ -83,14 +82,14 @@ Value available are: `NONE`, `IN-OPERATION`, `PROTOTYPE`, `PROJECT` and `OTHER`
### Gateway alert configuration

The contact phone and email are not required information on gateways. If these
values are not set, variables will be used as a fallback.
values are not set, the following variables will be used as a fallbacks.

* **ALERT_GATEWAY_FALLBACK_MAIL**
* **ALERT_GATEWAY_FALLBACK_PHONE**

### Device alert configuration

This application utilizes metadata on the device to add contact information.
This application utilizes metadata on the device to get contact information.
Since metadata consists of free-text key/value pairs, you can use the
configuration below to specify which keys should correspond to different contact
data.
Expand Down Expand Up @@ -141,7 +140,7 @@ This is the order of contact information fallback order.
**Gateways**:

* Command override
* Gateways contact information
* Gateway contact information
* Gateway fallback mail (.env)

**Devices**:
Expand All @@ -153,7 +152,7 @@ This is the order of contact information fallback order.

## Commands

If using Docker, they are executed in the `phpfpm` container by executing
If using Docker, commands are executed in the `phpfpm` container by executing
`bin/console`. All commands have `--help` option which will output text
explaining all the options and what they are used for.

Expand All @@ -163,7 +162,7 @@ For example, list all applications filtered on the configured statuses:
docker composer exec phpfpm bin/console app:api:applications --filter-status
```

The primary command for the application is `checks alert`, which runs the alert
The primary command for the application is `alert:checks`, which runs the alert
manager service. This command provides numerous options to modify its behavior;
use `--help` to view all available options.

Expand All @@ -179,28 +178,28 @@ The next command checks applications and thereby all devices found in the
applications.

```shell
docker composer exec phpfpm bin/console app:alert:checks --only-applications --filter-status
docker composer exec phpfpm bin/console app:alert:checks --only-applications
```

This command executes all tests and covers both gateways, applications (and
thereby devices).

```shell
docker composer exec phpfpm bin/console app:alert:checks --all --filter-status
docker composer exec phpfpm bin/console app:alert:checks --all
```

### API consumption test commands

Collection of commands to test and see information extracted from the IoT SPI.

* app:api:application (Get a single application from API server)
* app:api:applications (Get applications from API server)
* app:api:device (Get device from API server)
* app:api:gateways (Get gateways from API server)
* `app:api:application` (Get a single application from API server)
* `app:api:applications` (Get applications from API server)
* `app:api:device` (Get device from API server)
* `app:api:gateways` (Get gateways from API server)

### Mail/Sms test commands

Two commands to test mails and SMS integration.

* app:mail:test (Send test e-mail)
* app:sms:test (Send test SMS)
* `app:mail:test` (Send test e-mail)
* `app:sms:test` (Send test SMS)
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itkdev/iot_alter_manager",
"description": "IoT alter manager - IoT observability",
"name": "itkdev/iot_alert_manager",
"description": "IoT alert manager - IoT observability",
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
Expand Down
2 changes: 1 addition & 1 deletion src/Command/AlertChecksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
protected function configure(): void
{
$this
->addOption('date', null, InputOption::VALUE_REQUIRED, 'Overide date used to check (mostly for testing "'.$this->dateFormat.'")')
->addOption('date', null, InputOption::VALUE_REQUIRED, 'Override datetime used in checks for testing purposes. Use the format "'.$this->dateFormat.'")')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Run all checks')
->addOption('only-applications', null, InputOption::VALUE_NONE, 'Only check applications')
->addOption('only-gateways', null, InputOption::VALUE_NONE, 'Only check gateways')
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiApplicationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$msg = count($apps);
if ($filter) {
$msg .= sprintf(' applications found (filter on status "%s")', implode(',', $this->statuses));
$msg .= sprintf(' applications found (filtered on statuses "%s")', implode(',', $this->statuses));
} else {
$msg .= ' applications found';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiDeviceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$device = $this->apiClient->getDevice($id);

$output->writeln(json_encode($device, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$io->success('Successfully fetch data for device');
$io->success('Successfully fetched data for device');

return Command::SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiGatewaysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$msg = count($gateways);
if ($filter) {
$msg .= sprintf(' gateways found (filter on status "%s")', implode(',', $this->statuses));
$msg .= sprintf(' gateways found (filtered on statuses "%s")', implode(',', $this->statuses));
} else {
$msg .= ' applications found';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MailTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function configure(): void
{
$this
->addArgument('to', InputArgument::REQUIRED, 'The phone number to send SMS to')
->addOption('message', 'm', InputOption::VALUE_REQUIRED, 'Message to send', 'This is an IoT alter manager test')
->addOption('message', 'm', InputOption::VALUE_REQUIRED, 'Message to send', 'This is an IoT Alert Manager test')
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/SmsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function configure(): void
{
$this
->addArgument('to', InputArgument::REQUIRED, 'The phone number to send SMS to')
->addOption('msg', 'm', InputOption::VALUE_REQUIRED, 'Message to send', 'This is an IoT alter manager test')
->addOption('msg', 'm', InputOption::VALUE_REQUIRED, 'Message to send', 'This is an IoT Alert Manager test')
->addOption('flash', 'f', InputOption::VALUE_NONE, 'Send as flash message')
;
}
Expand Down
24 changes: 12 additions & 12 deletions src/Service/AlertManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
* @param \DateTimeImmutable $now
* Relative time to check against
* @param bool $filterOnStatus
* Filter based on the status given in configuration
* Filter based on the statuses given in configuration
* @param string $overrideMail
* Override the mail-address from the API with this address
* @param string $overridePhone
Expand Down Expand Up @@ -117,8 +117,8 @@ public function checkGateways(\DateTimeImmutable $now, bool $filterOnStatus = tr
}

$this->metricsService->counter(
name: 'alter_gateway_device_notification_tiggered_total',
help: 'Total number of alters triggered for gateways',
name: 'alert_gateway_device_notification_tiggered_total',
help: 'Total number of alerts triggered for gateways',
labels: ['type' => 'info']
);
}
Expand All @@ -131,7 +131,7 @@ public function checkGateways(\DateTimeImmutable $now, bool $filterOnStatus = tr
* @param \DateTimeImmutable $now
* Relative time to check against
* @param bool $filterOnStatus
* Filter based on the status given in configuration
* Filter based on the statuses given in configuration
* @param string $overrideMail
* Override the mail-address from the API with this address
* @param string $overridePhone
Expand Down Expand Up @@ -215,7 +215,7 @@ public function checkDevice(\DateTimeImmutable $now, int $deviceId, ?Application
// from.
if (is_null($device->latestReceivedMessage)) {
$this->metricsService->counter(
name: 'alter_message_missing_total',
name: 'alert_message_missing_total',
help: 'Device is missing latest received message',
labels: ['type' => 'info', 'id' => $device->id]
);
Expand Down Expand Up @@ -260,8 +260,8 @@ public function checkDevice(\DateTimeImmutable $now, int $deviceId, ?Application
}

$this->metricsService->counter(
name: 'alter_device_notification_tiggered_total',
help: 'Total number of alters triggered for devices',
name: 'alert_device_notification_tiggered_total',
help: 'Total number of alerts triggered for devices',
labels: ['type' => 'info']
);
}
Expand Down Expand Up @@ -413,7 +413,7 @@ private function skipBasedOnAppStartDate(Application $application): bool
private function isGatewaySilenced(Gateway $gateway): bool
{
if (isset($gateway->tags[$this->gatewaySilencedTag])) {
return $this->isPasteDate('gateway', $gateway->id, $gateway->tags[$this->gatewaySilencedTag]);
return $this->isPastDate('gateway', $gateway->id, $gateway->tags[$this->gatewaySilencedTag]);
}

return false;
Expand All @@ -433,7 +433,7 @@ private function isGatewaySilenced(Gateway $gateway): bool
private function isDeviceSilenced(Device $device): bool
{
if (isset($device->metadata[$this->deviceMetadataFieldSilenced])) {
return $this->isPasteDate('device', $device->id, $device->metadata[$this->deviceMetadataFieldSilenced]);
return $this->isPastDate('device', $device->id, $device->metadata[$this->deviceMetadataFieldSilenced]);
}

return false;
Expand All @@ -454,7 +454,7 @@ private function isDeviceSilenced(Device $device): bool
*
* @throws \DateInvalidTimeZoneException
*/
private function isPasteDate(string $type, int $id, string $strDate): bool
private function isPastDate(string $type, int $id, string $strDate): bool
{
$timezone = new \DateTimeZone($this->silencedTimezone);
$date = \DateTimeImmutable::createFromFormat($this->silencedTimeFormat, $strDate, $timezone);
Expand All @@ -468,12 +468,12 @@ private function isPasteDate(string $type, int $id, string $strDate): bool
}
$this->logger->error(sprintf('Silenced error at %s (%d):, %s', $type, $id, $errorMsg));
$this->metricsService->counter(
name: 'alter_silenced_parse_date_error_total',
name: 'alert_silenced_parse_date_error_total',
help: 'The total number of date parsing exceptions',
labels: ['type' => 'exception']
);

// Default to false, better get extra alter then non.
// Default to false. Better an extra alert rather than none.
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Service/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function __construct(
*/
public function getApplications(bool $filterOnStatus): array
{
// Currently the IoT API does not work correctly with offset and limits.
// Therefore, we use offset 0 and set limit high, .e.g. 999,
// to just get all applications.
$response = $this->iotApiClient->request('GET', '/api/v1/application', [
'query' => [
'offset' => 0,
Expand Down Expand Up @@ -121,6 +124,9 @@ public function getDevice(int $id): Device
*/
public function getGateways(bool $filterOnStatus): array
{
// Currently the IoT API does not work correctly with offset and limits.
// Therefore, we use offset 0 and set limit high, .e.g. 999,
// to just get all applications.
$response = $this->iotApiClient->request('GET', '/api/v1/chirpstack/gateway', [
'query' => [
'organizationId' => $this->gateWayOrgId,
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ApiParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private function parseDate(?string $dateString): \DateTimeImmutable
help: 'The total number of date parsing exceptions',
labels: ['type' => 'exception']
);
throw new ParsingException($errorMsg ?? 'Unknown data conversion error');
throw new ParsingException($errorMsg ?? 'Unknown date conversion error');
}

return $date->setTimezone($timezone);
Expand Down
4 changes: 2 additions & 2 deletions src/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public function __construct(
* @param array $context
* The context for the email template
* @param string $subject
* The subject of the email. Defaults to 'Test mail from alter manager'.
* The subject of the email. Defaults to 'Test mail from alert manager'.
* @param string $htmlTemplate
* The HTML template for the email. Defaults to 'test.html.twig'.
* @param string $textTemplate
* The text template for the email. Defaults to 'test.txt.twig'.
*
* @throws MailException
*/
public function sendEmail(string $to, array $context, string $subject = 'Test mail from alter manager', string $htmlTemplate = 'test.html.twig', string $textTemplate = 'test.txt.twig'): void
public function sendEmail(string $to, array $context, string $subject = 'Test mail from alert manager', string $htmlTemplate = 'test.html.twig', string $textTemplate = 'test.txt.twig'): void
{
$email = (new TemplatedEmail())
->from($this->fromAddress)
Expand Down
2 changes: 1 addition & 1 deletion templates/mails/device.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>Der var senest kontakt til "<a href="{{ url }}">{{ device.name }}</a>" {{ ago }}.</p>
<p>Der var senest kontakt til "<a href="{{ url }}">{{ device.name }}</a>" for {{ ago }} sekunder siden.</p>

<p>Seneste kontakt var <strong>{{ device.latestReceivedMessage.sentTime|date("d-m-Y H:i:s") }}</strong>.</p>

Expand Down
2 changes: 1 addition & 1 deletion templates/mails/device.txt.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Der var senest kontakt til "{{ device.name }}" {{ ago }}.
Der var senest kontakt til "{{ device.name }}" for {{ ago }} sekunder siden.

Seneste kontakt var {{ device.latestReceivedMessage.sentTime|date("d-m-Y H:i:s") }}.

Expand Down
2 changes: 1 addition & 1 deletion templates/mails/gateway.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>Der var senest kontakt til "<a href="{{ url }}">{{ gateway.name }}</a>" {{ ago }}.</p>
<p>Der var senest kontakt til "<a href="{{ url }}">{{ gateway.name }}</a>" for {{ ago }} sekunder siden.</p>

<p>Seneste kontakt var <strong>{{ gateway.lastSeenAt|date("d-m-Y H:i:s") }}.</strong></p>

Expand Down
2 changes: 1 addition & 1 deletion templates/mails/gateway.txt.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Der var senest kontakt til "{{ gateway.name }}" {{ ago }}.
Der var senest kontakt til "{{ gateway.name }}" for {{ ago }} sekunder siden.

Seneste kontakt var {{ gateway.lastSeenAt|date("d-m-Y H:i:s") }}.

Expand Down
2 changes: 1 addition & 1 deletion templates/mails/location.txt.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ type }} er registreret til at være placeret i punktet {{ latitude }}, {{ longitude }}

Se lokation på {% include 'mails/map_link.txt.twig' with { 'latitude': latitude, 'longitude': longitude } %}
Se placering på {% include 'mails/map_link.txt.twig' with { 'latitude': latitude, 'longitude': longitude } %}

2 changes: 1 addition & 1 deletion templates/mails/test.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>Der har ikke været kontakt til {{ name }} i {{ seenAgo }} skunder.</p>
<p>Der har ikke været kontakt til {{ name }} i {{ seenAgo }} sekunder.</p>

<p>Seneste kontakt var {{ lastSeenDate|date("d-m-Y H:i:s") }}.</p>

Expand Down
2 changes: 1 addition & 1 deletion templates/mails/test.txt.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Der har ikke været kontakt til {{ name }} i {{ seenAgo }} skunder.
Der har ikke været kontakt til {{ name }} i {{ seenAgo }} sekunder.

Seneste kontakt var {{ lastSeenDate|date("d-m-Y H:i:s") }}

Expand Down

0 comments on commit a9c2897

Please sign in to comment.