Skip to content

Commit

Permalink
Refactor code, add phpunit.xml and codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed May 2, 2017
1 parent 9ccc460 commit 61db48e
Show file tree
Hide file tree
Showing 32 changed files with 587 additions and 452 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -12,4 +12,4 @@ before_script:
- composer install -n

script:
- composer test
- vendor/bin/phpunit
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@ To get started, you will first need to have Monit installed with HTTP access ena
2. Add `config/servers.ini` (you can use [`servers.template.ini`](config/servers.template.ini))
3. Set up a crontab job to run cron every minute:
```cron
* * * * * cd /path/to/monit-graph && composer cron >> /var/log/monit-graph.log
* * * * * cd /path/to/monit-graph && php src/scripts/cron.php >> /var/log/monit-graph.log
```
4. Start server:
```bash
Expand Down
24 changes: 15 additions & 9 deletions composer.json
Expand Up @@ -5,31 +5,37 @@
"keywords": ["monit", "graph"],
"license": "BSD 3-clause",
"require": {
"php": ">=5.5.0",
"php": ">=5.6.0",
"slim/slim": "^3.1",
"slim/php-view": "^2.0",
"monolog/monolog": "^1.17",
"tuupola/slim-basic-auth": "^2.2"
},
"require-dev": {
"phpunit/phpunit": ">=4.8 < 6.0"
"phpunit/phpunit": ">=4.8",
"squizlabs/php_codesniffer": "^2.5"
},
"authors": [
{
"name": "Dan Schultzer",
"email": "dan@dreamconception.com"
}
],
"autoload-dev": {
"autoload": {
"psr-4": {
"Tests\\": "tests/"
"MonitGraph\\": "src/MonitGraph"
}
},
"scripts": {
"server": "php -S 0.0.0.0:8080 -t web/public web/public/index.php",
"test": "phpunit",
"cron": "php src/cron.php",
"build-massive-data": "php tests/utils/build_massive_data.php",
"reverse-xml": "php src/reverse_xml.php"
"server": "php -S 0.0.0.0:8080 -t src/web/public src/web/public/index.php",
"cron": "php src/scripts/cron.php",
"build-massive-data": "php tests/scripts/build_massive_data.php",
"reverse-xml": "php src/scripts/reverse_xml.php",
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "php vendor/bin/phpunit",
"phpcs": "php vendor/bin/phpcs"
}
}
80 changes: 79 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions config/config.default.php
@@ -1,29 +1,29 @@
<?php
if (!file_exists(__DIR__ . "/servers.ini")) {
die("Please set config/servers.ini first");
}
if (!file_exists(__DIR__ . "/servers.ini")) {
die("Please set config/servers.ini first");
}

return [
/* Monit-Graph display information */
'default_time_range' => 3600, // Amount in seconds of the default view should be (0 equals all available data)
'default_chart_type' => "LineChart", // Default chart type
'default_refresh_seconds' => 120, // Default amount of seconds before data is reloaded (0 equals never)
'default_specific_service' => "", // Default service to be displayed (none is equal to all services)
'default_dont_show_alerts' => "on",
'limit_records_shown' => 750,
return [
/* Monit-Graph display information */
'default_time_range' => 3600, // Amount in seconds of the default view should be (0 equals all available data)
'default_chart_type' => "LineChart", // Default chart type
'default_refresh_seconds' => 120, // Default amount of seconds before data is reloaded (0 equals never)
'default_specific_service' => "", // Default service to be displayed (none is equal to all services)
'default_dont_show_alerts' => "on",
'limit_records_shown' => 750,

/* Monit-Graph history handling */
'chunk_size' => 1024*1024, // Maximum size in bytes for each service history chunk (0 equals unlimited, remember to set php.ini so the scripts can handle it as well)
'limit_number_of_chunks' => 14, // Maximum number of chunks saved per service records, will delete all above this (0 equals unlimited)
/* Monit-Graph history handling */
'chunk_size' => 1024*1024, // Maximum size in bytes for each service history chunk (0 equals unlimited, remember to set php.ini so the scripts can handle it as well)
'limit_number_of_chunks' => 14, // Maximum number of chunks saved per service records, will delete all above this (0 equals unlimited)

'server_configs' => parse_ini_file(__DIR__ . "/servers.ini", true),
'server_configs' => parse_ini_file(__DIR__ . "/servers.ini", true),

'slimconfig' => [
'displayErrorDetails' => true, // set to false in production
'addContentLengthHeader' => false, // Allow the web server to send the content-length header
],
'slimconfig' => [
'displayErrorDetails' => true, // set to false in production
'addContentLengthHeader' => false, // Allow the web server to send the content-length header
],

// Basic authentication can be enabled. By default, ADMIN_PASSWORD environment variables
// is used. You can generate your own hashed password by running `htpasswd -nbBC 10 username password`
// 'basic_auth_users' => ['admin' => getenv('ADMIN_PASSWORD')]
];
// Basic authentication can be enabled. By default, ADMIN_PASSWORD environment variables
// is used. You can generate your own hashed password by running `htpasswd -nbBC 10 username password`
// 'basic_auth_users' => ['admin' => getenv('ADMIN_PASSWORD')]
];
18 changes: 18 additions & 0 deletions phpcs.xml
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<ruleset name="MonitGraph coding standard">
<description>MonitGraph coding standard</description>

<!-- display progress -->
<arg value="p"/>
<!-- use colors in output -->
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>tests</file>
</ruleset>
21 changes: 18 additions & 3 deletions phpunit.xml
@@ -1,7 +1,22 @@
<phpunit bootstrap="vendor/autoload.php">
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.7/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="MonitGraph">
<directory>tests</directory>
<testsuite name="MonitGraph Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 61db48e

Please sign in to comment.