/trunk/src/plugins/mybb_version/MyBbVersionCheck.class.php |
---|
0,0 → 1,80 |
<?php |
/* |
* VNag - Nagios Framework for PHP |
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
* Licensed under the terms of the Apache 2.0 license |
* |
* Revision 2024-04-29 |
*/ |
declare(ticks=1); |
class MyBbVersionCheck extends VNag { |
protected $argSystemDir = null; |
public function __construct() { |
parent::__construct(); |
$this->registerExpectedStandardArguments('Vvht'); |
$this->getHelpManager()->setPluginName('check_mybb_version'); |
$this->getHelpManager()->setVersion('2024-04-29'); |
$this->getHelpManager()->setShortDescription('This plugin checks if a local myBB system has the latest version installed.'); |
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
// Individual (non-standard) arguments: |
$this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'myBBPath', 'The local directory where your myBB installation is located.')); |
} |
protected function get_local_version($path) { |
$path = realpath($path) === false ? $path : realpath($path); |
$cont = @file_get_contents("$path/inc/class_core.php"); |
if (($cont === false) || |
!preg_match('@public \$version = "(.+)";@ismU', $cont, $m) || |
!preg_match('@public \$version_code = (.+);@ismU', $cont, $n)) |
{ |
throw new VNagException('Could not determinate current myBB version in "'.$path.'".'); |
} |
return array($version_code=$n[1], $version=$m[1]); |
} |
protected function cbRun($optional_args=array()) { |
$system_dir = $this->argSystemDir->getValue(); |
if (empty($system_dir)) { |
throw new VNagException("Please specify the directory of the myBB installation."); |
} |
$system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
if (!is_dir($system_dir)) { |
throw new VNagException('Directory "'.$system_dir.'" not found.'); |
} |
$versionCheckUrl = "https://mybb.com/version_check.php"; |
$cont = $this->url_get_contents($versionCheckUrl); |
if (($cont === false) || |
!preg_match('@<latest_version>(.+)</latest_version>@ismU', $cont, $m) || |
!preg_match('@<version_code>(\d+)</version_code>@ismU', $cont, $n)) |
{ |
throw new VNagException('Could not determinate latest myBB version'); |
} |
$latest_version = $m[1]; |
$latest_version_code = $n[1]; |
list($this_version_code, $this_version) = $this->get_local_version($system_dir); |
if ($this_version >= $latest_version) { |
$this->setStatus(VNag::STATUS_OK); |
$this->setHeadline("Version $this_version (Latest version) at $system_dir", true); |
} else { |
$this->setStatus(VNag::STATUS_WARNING); |
$this->setHeadline("Version $this_version (Latest version: $latest_version) at $system_dir", true); |
} |
} |
} |
/trunk/src/plugins/mybb_version/check_mybb_version.phps |
---|
0,0 → 1,18 |
<?php |
/* |
* VNag - Nagios Framework for PHP |
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
* Licensed under the terms of the Apache 2.0 license |
* |
* Revision 2018-07-15 |
*/ |
declare(ticks=1); |
require_once __DIR__ . '/../../framework/vnag_framework.inc.php'; |
require_once __DIR__ . '/MyBbVersionCheck.class.php'; |
$job = new MyBbVersionCheck(); |
$job->run(); |
unset($job); |
/trunk/src/plugins/mybb_version/icinga2.conf |
---|
0,0 → 1,49 |
// Put this file in /etc/icinga2/conf.d/... |
// VNag - Nagios Framework for PHP |
// Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
// Licensed under the terms of the Apache 2.0 license |
// |
// Revision 2024-04-29 |
object CheckCommand "vnag_mybb_version" { |
// PLEASE ADJUST THIS PATH |
command = [ "/daten/vnag/bin/mybb_version.phar" ] |
arguments = { |
"-d" = { |
value = "$vnag_mybb_version_dir$" |
description = "Location where the myBB installation is located" |
required = true |
} |
} |
} |
// Example usage: |
// |
// apply Service "example_website1_mybb_version" { |
// import "generic-service" |
// check_command = "vnag_mybb_version" |
// vars = { |
// vnag_mybb_version_dir = "/var/www/website1/mybb/" |
// } |
// assign where host.name == NodeName |
// } |
// |
// apply Service "example_website2_mybb_version" { |
// import "generic-service" |
// check_command = "vnag_mybb_version" |
// vars = { |
// vnag_mybb_version_dir = "/var/www/website2/mybb/" |
// } |
// assign where host.name == NodeName |
// } |
// |
// apply Service "example_website3_mybb_version" { |
// import "generic-service" |
// check_command = "vnag_mybb_version" |
// vars = { |
// vnag_mybb_version_dir = "/var/www/website3/mybb/" |
// } |
// assign where host.name == NodeName |
// } |
/trunk/src/plugins/simplemachines_version/SmfVersionCheck.class.php |
---|
0,0 → 1,77 |
<?php |
/* |
* VNag - Nagios Framework for PHP |
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
* Licensed under the terms of the Apache 2.0 license |
* |
* Revision 2024-04-29 |
*/ |
declare(ticks=1); |
class SmfVersionCheck extends VNag { |
protected $argSystemDir = null; |
public function __construct() { |
parent::__construct(); |
$this->registerExpectedStandardArguments('Vvht'); |
$this->getHelpManager()->setPluginName('check_smf_version'); |
$this->getHelpManager()->setVersion('2024-04-29'); |
$this->getHelpManager()->setShortDescription('This plugin checks if a local SimpleMachinesForum system has the latest version installed.'); |
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
// Individual (non-standard) arguments: |
$this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'smfPath', 'The local directory where your SimpleMachinesForum installation is located.')); |
} |
protected function get_local_version($path) { |
$path = realpath($path) === false ? $path : realpath($path); |
$cont = @file_get_contents("$path/index.php"); |
if (($cont === false) || |
!preg_match("@define\('SMF_VERSION', '(.+)'\);@ismU", $cont, $m)) |
{ |
throw new VNagException('Could not determinate current SimpleMachinesForum version in "'.$path.'".'); |
} |
return $version=$m[1]; |
} |
protected function cbRun($optional_args=array()) { |
$system_dir = $this->argSystemDir->getValue(); |
if (empty($system_dir)) { |
throw new VNagException("Please specify the directory of the SimpleMachinesForum installation."); |
} |
$system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
if (!is_dir($system_dir)) { |
throw new VNagException('Directory "'.$system_dir.'" not found.'); |
} |
$versionCheckUrl = "https://www.simplemachines.org/smf/current-version.js"; |
$cont = $this->url_get_contents($versionCheckUrl); |
if (($cont === false) || |
!preg_match('@window.smfVersion = "SMF (.+)";@ismU', $cont, $m)) |
{ |
throw new VNagException('Could not determinate latest SimpleMachinesForum version'); |
} |
$latest_version = $m[1]; |
$this_version = $this->get_local_version($system_dir); |
if (version_compare($this_version,$latest_version) >= 0) { |
$this->setStatus(VNag::STATUS_OK); |
$this->setHeadline("Version $this_version (Latest version) at $system_dir", true); |
} else { |
$this->setStatus(VNag::STATUS_WARNING); |
$this->setHeadline("Version $this_version (Latest version: $latest_version) at $system_dir", true); |
} |
} |
} |
/trunk/src/plugins/simplemachines_version/icinga2.conf |
---|
0,0 → 1,49 |
// Put this file in /etc/icinga2/conf.d/... |
// VNag - Nagios Framework for PHP |
// Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
// Licensed under the terms of the Apache 2.0 license |
// |
// Revision 2024-04-29 |
object CheckCommand "vnag_simplemachines_version" { |
// PLEASE ADJUST THIS PATH |
command = [ "/daten/vnag/bin/simplemachines_version.phar" ] |
arguments = { |
"-d" = { |
value = "$vnag_simplemachines_version_dir$" |
description = "Location where the SimpleMachinesForum installation is located" |
required = true |
} |
} |
} |
// Example usage: |
// |
// apply Service "example_website1_simplemachines_version" { |
// import "generic-service" |
// check_command = "vnag_simplemachines_version" |
// vars = { |
// vnag_simplemachines_version_dir = "/var/www/website1/smf/" |
// } |
// assign where host.name == NodeName |
// } |
// |
// apply Service "example_website2_simplemachines_version" { |
// import "generic-service" |
// check_command = "vnag_simplemachines_version" |
// vars = { |
// vnag_simplemachines_version_dir = "/var/www/website2/smf/" |
// } |
// assign where host.name == NodeName |
// } |
// |
// apply Service "example_website3_simplemachines_version" { |
// import "generic-service" |
// check_command = "vnag_simplemachines_version" |
// vars = { |
// vnag_simplemachines_version_dir = "/var/www/website3/smf/" |
// } |
// assign where host.name == NodeName |
// } |
/trunk/src/plugins/simplemachines_version/simplemachines_version.phps |
---|
0,0 → 1,18 |
<?php |
/* |
* VNag - Nagios Framework for PHP |
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
* Licensed under the terms of the Apache 2.0 license |
* |
* Revision 2018-07-15 |
*/ |
declare(ticks=1); |
require_once __DIR__ . '/../../framework/vnag_framework.inc.php'; |
require_once __DIR__ . '/SmfVersionCheck.class.php'; |
$job = new SmfVersionCheck(); |
$job->run(); |
unset($job); |