Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add curl options to allow running check_opcache by Nagios agents #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cli/check_opcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@

// Get cli options.
list($options, $unrecognized) = cli_get_params(['help' => false,
'verbose' => 0,
'insecure' => 0,
'url' => null,
'domain' => null,
'warning' => 80,
'critical' => 90, ],
['h' => 'help',
'v' => 'verbose',
'i' => 'insecure',
'u' => 'url',
'd' => 'domain',
'w' => 'warning',
'c' => 'critical', ]);
if ($unrecognized) {
Expand All @@ -55,8 +61,11 @@

Options:
-u, --url Full URL to check_opcache_web.php
-d, --domain Domain, useful when it use IP in the URL
-w, --warning Threshold for warning (Default: 80)
-c, --critical Threshold for critical (Default: 90)
-i, --insecure When true, sets the SSL_VERIFYPEER and SSL_VERIFYHOST options to false
-v, --verbose Verbose
-h, --help Print out this help

Example:
Expand All @@ -72,18 +81,24 @@
$options['url'] = clean_param($options['url'], PARAM_URL);
$options['warning'] = clean_param($options['warning'], PARAM_INT);
$options['critical'] = clean_param($options['critical'], PARAM_INT);
$options['insecure'] = clean_param($options['insecure'], PARAM_BOOL);
$options['verbose'] = clean_param($options['verbose'], PARAM_BOOL);


// Fetch Opcache figures from webserver.
$curl = new curl(['ignoresecurity' => true]); // The ignoresecurity option means that $CFG->curlsecurityblockedhosts is
// ignored by purpose. Otherwise, $CFG->curlsecurityblockedhosts might prevent
// that the web part of this CLI tool is fetched.
$curloptions = [
'VERBOSE' => $options['verbose'],
'FRESH_CONNECT' => true,
'RETURNTRANSFER' => true,
'FORBID_REUSE' => true,
'HEADER' => false,
'CONNECTTIMEOUT' => 5,
'HTTPHEADER' => array("Host: ".$options['domain']),
'SSL_VERIFYPEER' => ($options['insecure'] ? 0:1),
'SSL_VERIFYHOST' => ($options['insecure'] ? 0:1)
];
$params = [];
if (isset($CFG->tool_opcache_check_secretkey)) {
Expand Down