Rev 4 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4 | Rev 54 | ||
---|---|---|---|
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | A/Ae4mLugX8aWi3kU6+IP3v8vJqavUp5B0oOzj6LG/H28D/deFDPma4ukxYN933EN |
2 | ISLdljjtzCdnwu/ldQDVktIeOGgqR6kkmK0B//MwT0fqh8qhLOqyRpLJnVMxaN6Ta |
3 | 3jWEdDAPnJYHnAnicrW6X037PjLCDDfCFSI0Ag7uERGhacn0+jjtD8HlUp1Rx1vmw |
3 | bfjTM0gb/OhxWiU3+WDI4bN+jwuk+X5j3NVre3JiTKXr39WoxF/aKIUuloeej931e |
4 | GbMVnhwbZaTHb1579ASAEE+s06LC21zzaAovhaQbe+zQpSMyUijBU7QuiOT93DHZj |
4 | mXu1CGjaXC2xp7B20vMkf+wfLNnwebMKvIgceR4Qwq76FRSygPeJtfcWIaG1oWywT |
5 | RsxmZe5RUU8DIQ55hYj70k3iiVkN7QKss700e6dtfctedZxSThXIjFLWgv/8PAQNV |
5 | Rz1laiI5VNRaBHqVjfcdo4zCVkpwepC9SHICrTsD3cfBe+p8t5jsbYd5g2Z6V5u2r |
6 | sIzpb/T9EbqiibvsWDWGn30pVjDsGLltOM8+iakOwaY5/0lO5DEfLUuChV1d2CZpz |
6 | zvGXA3oZowPTiw+ZnhPiIqdQKshFhEsnfM+unpElkLwM+4a8k+JPYSbNAjhqdL8XY |
7 | vH8QHD8iG2ur4i4JJyJ953yzvKO5ewFsOFKupHAR1QyTMYGyd+wtBLsiRYw7IJgsv |
7 | CE32SAY2wsH6CAIhOpwRN2p4QDs8Kk0U3EeIq6vONyjP9WYj7SWkssnZtQA/5K93O |
8 | kF7Z3XUzuwoVhnsDReF9jH2IG6R1rH0CuOAMspnD+PravAeFCSOJY2XVN0eJZmSNZ |
8 | 0uLhqcXCnsWKFzwuuDfIQGdfnkyXyoKp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v |
16 | u8FOnIcK2koM/FqZydvbqC3AYcoxSCccsogc7KARUMtKt7v4OY2HvTZ7IMudoRmtS |
17 | u2xMI8LD22KsgZh+IYQtsfBMtfs9UBXGVBOg6W6BSpCivBUqT+M5PDz3VAB39dB+q |
17 | FfJzwMZHzv/eqgTlgBOoG9xmtdn04nYucEUss9Pyv9eAb17wDa5x88cTldkCacPy2 |
18 | aWs1wgkhAN/7/Uqo4DyjheoIYVzChgyX8p/zC9m62ppAhwr4aIrEdtrCsiI1SpBWA |
18 | ub6eVI9Z2GKSGHpz9+IPY9XwXxn69lVIHmRM2Ngs6qP2lOsseQZmUABt6lXtupv4W |
19 | eCIKMzXU1FdY96f+EgnJzCD5ViENvkx58HiLUURl4SLYX/YYinVn2m2yS4mIk02S5 |
19 | qlPMjP67OcVFGUgqMABxOm+ooRtUiGeKEUF11qxda9bF993Kco6QLDUU/ggXt5lhL |
20 | LEU6tgGjnDdc82KGQLDDQKjU5w9/xz08SIRqwn5PpGeisv3EYoj/9KandHgAU9fDp |
20 | qK4+EnLjPpMsqGa/EOe0kcqBS/+Goj/yz7ot50hZTxDWs7lq29VDZqdaYvdKmrYyb |
21 | 2qkurm42hGkly4avVs7H58xVrzXW0pP2NW/fJEUOoYqSWZp9bE+Jgr7Y2etBdov2y |
21 | h169//lL0XytrNCDyZE3WiWUnKvS0nl3gfpOxWPI4vflx2rli8mF56e7COgAASlNI |
22 | 0kNYaeil4VKsM/m/cIFBs9RmsGmSaBamsj0WMrCuiM9jTDZcj2q0wqvd/yRoIuMny |
22 | K9TsrfGFmZ+yfK4cgHRehkAVq85Ym8KLfoZQOGDRpi/ZVeNHJhRfacyBow5pteKVL |
23 | Q== |
23 | Q== |
24 | </ViaThinkSoftSignature> */ ?> |
24 | </ViaThinkSoftSignature> */ ?> |
25 | <?php |
25 | <?php |
26 | 26 | ||
27 | /* |
27 | /* |
28 | * VNag - Nagios Framework for PHP |
28 | * VNag - Nagios Framework for PHP |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
30 | * Licensed under the terms of the Apache 2.0 license |
30 | * Licensed under the terms of the Apache 2.0 license |
31 | * |
31 | * |
32 | * Revision 2018-07-15 |
32 | * Revision 2022-07-17 |
33 | */ |
33 | */ |
34 | 34 | ||
35 | declare(ticks=1); |
35 | declare(ticks=1); |
36 | 36 | ||
37 | class VNagWebReader extends VNag { |
37 | class VNagWebReader extends VNag { |
38 | protected $argUrl = null; |
38 | protected $argUrl = null; |
39 | protected $argId = null; |
39 | protected $argId = null; |
40 | protected $argBasicAuth = null; |
40 | protected $argBasicAuth = null; |
41 | protected $argPassword = null; |
41 | protected $argPassword = null; |
42 | protected $argSignPubKey = null; |
42 | protected $argSignPubKey = null; |
43 | 43 | ||
44 | public function __construct() { |
44 | public function __construct() { |
45 | parent::__construct(); |
45 | parent::__construct(); |
46 | 46 | ||
47 | if ($this->is_http_mode()) { |
47 | if ($this->is_http_mode()) { |
48 | // Don't allow the standard arguments via $_REQUEST |
48 | // Don't allow the standard arguments via $_REQUEST |
49 | $this->registerExpectedStandardArguments(''); |
49 | $this->registerExpectedStandardArguments(''); |
50 | } else { |
50 | } else { |
51 | $this->registerExpectedStandardArguments('Vht'); |
51 | $this->registerExpectedStandardArguments('Vht'); |
52 | } |
52 | } |
53 | $this->addExpectedArgument($this->argUrl = new VNagArgument('u', 'url', VNagArgument::VALUE_REQUIRED, 'url', 'The URI of the page that contains an embedded machine readable VNag output', null)); |
53 | $this->addExpectedArgument($this->argUrl = new VNagArgument('u', 'url', VNagArgument::VALUE_REQUIRED, 'url', 'The URI of the page that contains an embedded machine readable VNag output', null)); |
54 | $this->addExpectedArgument($this->argId = new VNagArgument('i', 'id', VNagArgument::VALUE_REQUIRED, 'id', 'The ID (serial or individual name) of the embedded Nagios output. Usually "0" if only one monitor is used without individual names.', '0')); |
54 | $this->addExpectedArgument($this->argId = new VNagArgument('i', 'id', VNagArgument::VALUE_REQUIRED, 'id', 'The ID (serial or individual name) of the embedded Nagios output. Usually "0" if only one monitor is used without individual names.', '0')); |
55 | $this->addExpectedArgument($this->argBasicAuth = new VNagArgument('b', 'basicAuth', VNagArgument::VALUE_REQUIRED, 'username:password', 'In case the target website requires Basic Auth, please pass username and password, divided by double-colon, into this argument.', null)); |
55 | $this->addExpectedArgument($this->argBasicAuth = new VNagArgument('b', 'basicAuth', VNagArgument::VALUE_REQUIRED, 'username:password', 'In case the target website requires Basic Auth, please pass username and password, divided by double-colon, into this argument.', null)); |
56 | $this->addExpectedArgument($this->argPassword = new VNagArgument('p', 'password', VNagArgument::VALUE_REQUIRED, 'password', 'In case the machine readable VNag output is encrypted, enter the password here.', null)); |
56 | $this->addExpectedArgument($this->argPassword = new VNagArgument('p', 'password', VNagArgument::VALUE_REQUIRED, 'password', 'In case the machine readable VNag output is encrypted, enter the password here.', null)); |
57 | $this->addExpectedArgument($this->argSignPubKey = new VNagArgument('k', 'signPubKey', VNagArgument::VALUE_REQUIRED, 'pemFile', 'In case the machine readable VNag output is signed, enter the filename of the public key (PEM) file here, to verify the signature of the output.', null)); |
57 | $this->addExpectedArgument($this->argSignPubKey = new VNagArgument('k', 'signPubKey', VNagArgument::VALUE_REQUIRED, 'pemFile', 'In case the machine readable VNag output is signed, enter the filename of the public key (PEM) file here, to verify the signature of the output.', null)); |
58 | 58 | ||
59 | $this->getHelpManager()->setPluginName('vnag_webreader'); |
59 | $this->getHelpManager()->setPluginName('vnag_webreader'); |
60 | $this->getHelpManager()->setVersion('1.0'); |
60 | $this->getHelpManager()->setVersion('1.0'); |
61 | $this->getHelpManager()->setShortDescription('This plugin reads embedded machine readable VNag output from a website and converts it into a Nagios compatible output format.'); |
61 | $this->getHelpManager()->setShortDescription('This plugin reads embedded machine readable VNag output from a website and converts it into a Nagios compatible output format.'); |
62 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
62 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
63 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -u <url> [-i <id>] [-b <username>:<password>] [-k pubKeyFile] [-p <password>]'); |
63 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -u <url> [-i <id>] [-b <username>:<password>] [-k pubKeyFile] [-p <password>]'); |
64 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
64 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
65 | } |
65 | } |
66 | 66 | ||
67 | protected function cbRun() { |
67 | protected function cbRun() { |
68 | $this->argUrl->require(); |
68 | $this->argUrl->require(); |
69 | $this->argId->require(); |
69 | $this->argId->require(); |
70 | 70 | ||
71 | $url = $this->argUrl->getValue(); |
71 | $url = $this->argUrl->getValue(); |
72 | $this->id = $this->argId->getValue(); // default is '0', so we do not need to check for available() |
72 | $this->id = $this->argId->getValue(); // default is '0', so we do not need to check for available() |
73 | if ($this->argPassword->available()) $this->password_in = $this->argPassword->getValue(); |
73 | if ($this->argPassword->available()) $this->password_in = $this->argPassword->getValue(); |
74 | if ($this->argSignPubKey->available()) $this->pubkey = $this->argSignPubKey->getValue(); |
74 | if ($this->argSignPubKey->available()) $this->pubkey = $this->argSignPubKey->getValue(); |
75 | 75 | ||
76 | $options = array( |
76 | $options = array( |
77 | 'http' => array( |
77 | 'http' => array( |
78 | 'method' => 'GET', |
78 | 'method' => 'GET', |
79 | 'header' => |
79 | 'header' => |
80 | sprintf("Authorization: Basic %s\r\n", base64_encode($this->argBasicAuth->getValue())). |
80 | sprintf("Authorization: Basic %s\r\n", base64_encode($this->argBasicAuth->getValue())). |
81 | sprintf("User-Agent: PHP/%s Vag/%s\r\n", phpversion(), self::VNAG_VERSION) |
81 | sprintf("User-Agent: PHP/%s VNag/%s\r\n", phpversion(), self::VNAG_VERSION) |
82 | ) |
82 | ) |
83 | ); |
83 | ); |
84 | $context = stream_context_create($options); |
84 | $context = stream_context_create($options); |
85 | $cont = file_get_contents($url, false, $context); |
85 | $cont = file_get_contents($url, false, $context); |
86 | if (!$cont) throw new VNagException("Cannot access $url"); |
86 | if (!$cont) throw new VNagException("Cannot access $url"); |
87 | 87 | ||
88 | $data = $this->readInvisibleHTML($cont); |
88 | $data = $this->readInvisibleHTML($cont); |
89 | 89 | ||
90 | if (!$data) throw new VNagInvalidArgumentException("No monitor with ID \"$this->id\" found at URL $url"); |
90 | if (!$data) throw new VNagInvalidArgumentException("No monitor with ID \"$this->id\" found at URL $url"); |
91 | 91 | ||
92 | if (isset($data['text'])) { |
92 | if (isset($data['text'])) { |
93 | $this->setHeadline("Special content delivered from the web monitor (see verbose info)"); |
93 | $this->setHeadline("Special content delivered from the web monitor (see verbose info)"); |
94 | $this->addVerboseMessage($data['text'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor |
94 | $this->addVerboseMessage($data['text'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor |
95 | } else { |
95 | } else { |
96 | foreach ($data['performance_data'] as $perfdata) { |
96 | foreach ($data['performance_data'] as $perfdata) { |
97 | $this->addPerformanceData(VNagPerformanceData::createByString($perfdata)); |
97 | $this->addPerformanceData(VNagPerformanceData::createByString($perfdata)); |
98 | } |
98 | } |
99 | 99 | ||
100 | $this->setHeadline($data['headline']); |
100 | $this->setHeadline($data['headline']); |
101 | $this->addVerboseMessage($data['verbose_info'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor |
101 | $this->addVerboseMessage($data['verbose_info'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor |
102 | } |
102 | } |
103 | 103 | ||
104 | $this->setStatus($data['status'], true); |
104 | $this->setStatus($data['status'], true); |
105 | } |
105 | } |
106 | } |
106 | } |
107 | 107 |