PHP code example of apermo / site-bookkeeper-reporter
1. Go to this page and download the library: Download apermo/site-bookkeeper-reporter library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
apermo / site-bookkeeper-reporter example snippets
define( 'SITE_BOOKKEEPER_HUB_URL', 'https://monitor.example.tld' );
define( 'SITE_BOOKKEEPER_TOKEN', 'your-site-token-here' );
define( 'SITE_BOOKKEEPER_ALLOW_HTTP', true );
add_filter( 'site_bookkeeper_custom_fields', function ( array $fields ): array {
$fields[] = [
'key' => 'my_check',
'label' => 'My Custom Check',
'value' => 'All good',
'status' => 'good', // good, warning, critical, or omit
];
return $fields;
} );
bash
#!/usr/bin/env bash
set -euo pipefail
HUB_URL="https://monitor.example.tld"
HUB_CLI="php /path/to/site-bookkeeper-hub/bin/manage.php"
SITES_FILE="./sites.txt" # One SSH path per line, e.g. user@host:/var/www/site
while IFS= read -r ssh_path; do
[[ -z "${ssh_path}" || "${ssh_path}" == \#* ]] && continue
echo "--- Setting up ${ssh_path} ---"
site_url=$(wp --ssh="${ssh_path}" option get siteurl)
token=$($HUB_CLI site:add "${site_url}" --label="${ssh_path}" 2>&1 | grep "Bearer token" -A1 | tail -1 | tr -d ' ')
wp --ssh="${ssh_path}" config set SITE_BOOKKEEPER_HUB_URL "${HUB_URL}" --type=constant --raw
wp --ssh="${ssh_path}" config set SITE_BOOKKEEPER_TOKEN "${token}" --type=constant --raw
wp --ssh="${ssh_path}" plugin activate site-bookkeeper-reporter
wp --ssh="${ssh_path}" bookkeeper-reporter report
echo " ${site_url} → registered and reporting"
done < "${SITES_FILE}"
bash
php bin/manage.php network:add https://network.example.tld --label="My Network"