Skip to content

Commit 49cdc32

Browse files
committed
Update to PHP 8.2
* add PHP Coding Standards Fixer configuration * add numbered headings to README * add table of contents to README * add GitHub actions support * add strict types * update to PHP 8.2 language level * update PHP version requirement to 8.2 * update to PHPUnit 9 * update links to use HTTPS * update copyright * change PHPUnit configuration to use Composer autoloader * change build badge to GitHub action * remove behat dev dependency * remove phpspec dev dependency * remove empty directories * remove Travis CI configuration
1 parent ab7ef27 commit 49cdc32

23 files changed

Lines changed: 696 additions & 500 deletions

File tree

.github/workflows/php.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: PHP Composer
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
- release/*
9+
pull_request:
10+
branches:
11+
- master
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- name: Validate composer.json and composer.lock
25+
run: composer validate --strict
26+
27+
- name: Cache Composer packages
28+
id: composer-cache
29+
uses: actions/cache@v3
30+
with:
31+
path: vendor
32+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-php-
35+
36+
- name: Install dependencies
37+
run: composer install --prefer-dist --no-progress
38+
39+
- name: Run test suite
40+
run: composer run-script test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.build
22
.idea
3+
.php-cs-fixer.cache
4+
.php_cs.cache
5+
.phpunit.result.cache
36
.tmp
47
composer.lock
58
nbproject

.php-cs-fixer.dist.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* PHP Code Style Fixer configuration.
4+
*
5+
* @author Ch'Ih-Yu <chi-yu@web.de>
6+
* @copyright 2025 Random-Host.tv
7+
* @license https://opensource.org/licenses/BSD-3-Clause BSD License (3 Clause)
8+
*
9+
* @see https://github.random-host.tv
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace PhpCsFixer;
15+
16+
$finder = Finder::create()
17+
->ignoreDotFiles(false)
18+
->ignoreVCSIgnored(true)
19+
;
20+
21+
$config = new Config();
22+
$config
23+
->setFinder($finder)
24+
->setRiskyAllowed(true)
25+
->setRules([
26+
'@PhpCsFixer' => true,
27+
'phpdoc_annotation_without_dot' => false,
28+
'php_unit_test_class_requires_covers' => false,
29+
'php_unit_internal_class' => false,
30+
'phpdoc_to_comment' => false,
31+
])
32+
;
33+
34+
return $config;

.travis.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2018 random-host.com
3+
Copyright (c) 2025 Random-Host.tv
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,77 @@
1-
[![Build Status][0]][1]
1+
[![Build Status][1]][2]
22

3-
randomhost/icinga-notification
4-
==============================
3+
# randomhost/icinga-notification
54

6-
This package provides a set of common notification commands to a accompany the
7-
`randomhost/icinga` package.
5+
<!-- TOC -->
6+
* [1. Purpose](#1-purpose)
7+
* [2. Usage](#2-usage)
8+
* [2.1. CM.com](#21-cmcom)
9+
* [2.1.1. Usage Example](#211-usage-example)
10+
* [2.1.2. Command Line Parameters](#212-command-line-parameters)
11+
* [3. License](#3-license)
12+
<!-- TOC -->
813

9-
Usage
10-
-----
14+
## 1. Purpose
1115

12-
`NotifyMyAndroid` is currently the only available notification plugin but more
13-
will follow in the future.
16+
This package provides a set of common notification commands to accompany the
17+
[`randomhost/icinga`][3] package.
1418

15-
### NotifyMyAndroid
19+
## 2. Usage
1620

17-
Sends notifications using [NotifyMyAndroid][2].
21+
`CmDotCom` is currently the only available notification plugin.
1822

19-
#### Usage example
23+
### 2.1. CM.com
24+
25+
Sends notifications using [CM.com][4].
26+
27+
#### 2.1.1. Usage Example
2028

2129
```php
2230
<?php
23-
namespace randomhost\Icinga\Notification;
2431

25-
require_once '/path/to/vendor/autoload.php';
32+
use randomhost\Icinga\Notification\CmDotCom\Factory;
2633

27-
use randomhost\NotifyMyAndroid\Client as NmaClient;
34+
include $_composer_autoload_path ?? __DIR__.'/../../vendor/autoload.php';
2835

29-
$nmaClient = new NmaClient();
30-
31-
$notification = new NotifyMyAndroid($nmaClient);
32-
$notification->setOptions(
33-
getopt(
34-
$notification->getShortOptions(),
35-
$notification->getLongOptions()
36+
$notification = (new Factory())->getNotification();
37+
$notification
38+
->setOptions(
39+
getopt(
40+
$notification->getShortOptions(),
41+
$notification->getLongOptions()
42+
)
3643
)
37-
);
38-
$notification->run();
44+
->run()
45+
;
3946

4047
echo $notification->getMessage();
48+
4149
exit($notification->getCode());
4250
```
4351

44-
This will instantiate the NotifyMyAndroid notification plugin and send a push
45-
notification to the NMA API key provided on the command line.
52+
This will instantiate the CM.com notification plugin and send a text message to
53+
the phone number provided on the command line.
4654

47-
#### Command line parameters
55+
#### 2.1.2. Command Line Parameters
4856

49-
| Parameter | Description |
50-
| ------------------- | ----------------------- |
51-
| --type | Notification type |
52-
| --service | Service name |
53-
| --host | Host name |
54-
| --address | Host address |
55-
| --state | Service state |
56-
| --time | Notification time |
57-
| --output | Check plugin output |
58-
| --apikey | NotifyMyAndroid API key |
57+
| Parameter | Description |
58+
|-------------|----------------------------------------------------------|
59+
| `--type` | Notification type |
60+
| `--service` | Service name |
61+
| `--host` | Host name |
62+
| `--address` | Host address |
63+
| `--state` | Service state |
64+
| `--time` | Notification time |
65+
| `--output` | Check plugin output |
66+
| `--phone` | Phone number in international format (e.g. +12065550199) |
67+
| `--apikey` | CM.com API key |
5968

60-
License
61-
-------
69+
## 3. License
6270

6371
See LICENSE.txt for full license details.
6472

6573

66-
[0]: https://travis-ci.org/randomhost/icinga-notification.svg?branch=master
67-
[1]: https://travis-ci.org/randomhost/icinga-notification
68-
[2]: http://notifymyandroid.com
74+
[1]: https://github.com/randomhost/icinga-notification/actions/workflows/php.yml/badge.svg
75+
[2]: https://github.com/randomhost/icinga-notification/actions/workflows/php.yml
76+
[3]: https://github.com/randomhost/icinga-notification
77+
[4]: https://cm.com

composer.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Icinga",
77
"Nagios"
88
],
9-
"homepage": "https://www.random-host.com",
9+
"homepage": "https://github.random-host.tv",
1010
"license": "BSD-3-Clause",
1111
"authors": [
1212
{
@@ -16,25 +16,31 @@
1616
],
1717
"config": {
1818
"platform": {
19-
"php": "5.3.3"
19+
"php": "8.2.29"
2020
}
2121
},
2222
"require": {
23-
"php": ">=5.3.0",
24-
"randomhost/icinga": "~0.2.1",
25-
"randomhost/notifymyandroid": "~0.0.2"
23+
"php": ">=8.2.0",
24+
"composer-runtime-api": "^2.2",
25+
"randomhost/icinga": "~1.0.0",
26+
"cmdotcom/text-sdk-php": "^2.2"
2627
},
2728
"require-dev": {
28-
"behat/behat": "~2.0",
29-
"phpunit/phpunit": "~4.0",
30-
"phpspec/phpspec": "~2.4"
29+
"phpunit/phpunit": "~9.0",
30+
"phpspec/prophecy": "^1.16",
31+
"phpspec/prophecy-phpunit": "^2.0"
3132
},
32-
"bin": [
33-
"src/bin/icinga-notify-nma-push"
34-
],
3533
"autoload": {
3634
"psr-4": {
3735
"randomhost\\Icinga\\Notification\\": "src/php/"
3836
}
37+
},
38+
"autoload-dev": {
39+
"psr-4": {
40+
"randomhost\\Icinga\\Notification\\Tests\\": "src/tests/php"
41+
}
42+
},
43+
"scripts": {
44+
"test": "vendor/bin/phpunit"
3945
}
4046
}

phpunit.xml.dist

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
<?xml version="1.0"?>
2-
<phpunit bootstrap="src/tests/bootstrap.php">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
4+
<coverage includeUncoveredFiles="true">
5+
<include>
6+
<directory suffix=".php">src/php</directory>
7+
</include>
8+
<report>
9+
<clover outputFile="review/logs/phpunit.xml"/>
10+
<html outputDirectory="review/code-coverage"/>
11+
</report>
12+
</coverage>
313
<testsuites>
414
<testsuite name="Unit_Tests">
5-
<directory suffix="Test.php">src/tests/unit-tests</directory>
15+
<directory suffix="Test.php">src/tests/php</directory>
616
</testsuite>
717
</testsuites>
8-
<testsuites>
9-
<testsuite name="Functional_Tests">
10-
<directory suffix="Test.php">src/tests/functional-tests</directory>
11-
</testsuite>
12-
</testsuites>
13-
<filter>
14-
<blacklist>
15-
<directory suffix=".php">vendor</directory>
16-
<directory suffix=".php">src/tests</directory>
17-
</blacklist>
18-
<whitelist addUncoveredFilesFromWhitelist="true">
19-
<directory suffix=".php">src/bin</directory>
20-
<directory suffix=".php">src/php</directory>
21-
</whitelist>
22-
</filter>
2318
<logging>
24-
<log type="coverage-html" target="review/code-coverage"/>
25-
<log type="coverage-clover" target="review/logs/phpunit.xml"/>
26-
<log type="json" target="review/logs/phpunit.json"/>
27-
<log type="tap" target="review/logs/phpunit.tap"/>
28-
<log type="junit" target="review/logs/phpunit-junit.xml"/>
29-
<log type="testdox-html" target="review/testdox.html"/>
30-
<log type="testdox-text" target="review/testdox.txt"/>
19+
<junit outputFile="review/logs/phpunit-junit.xml"/>
20+
<testdoxHtml outputFile="review/testdox.html"/>
21+
<testdoxText outputFile="review/testdox.txt"/>
3122
</logging>
3223
</phpunit>
33-

src/bin/cmtext.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* Sends Icinga SMS notifications via CM.com.
6+
*
7+
* @author Ch'Ih-Yu <chi-yu@web.de>
8+
* @copyright 2025 Random-Host.tv
9+
* @license https://opensource.org/licenses/BSD-3-Clause BSD License (3 Clause)
10+
*
11+
* @see https://github.random-host.tv
12+
*/
13+
14+
use randomhost\Icinga\Notification\CmDotCom\Factory;
15+
16+
include $_composer_autoload_path ?? __DIR__.'/../../vendor/autoload.php';
17+
18+
$notification = (new Factory())->getNotification();
19+
$notification
20+
->setOptions(
21+
getopt(
22+
$notification->getShortOptions(),
23+
$notification->getLongOptions()
24+
)
25+
)
26+
->run()
27+
;
28+
29+
echo $notification->getMessage();
30+
31+
exit($notification->getCode());

src/bin/icinga-notify-nma-push

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)