Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature>A/Ae4mLugX8aWi3kU6+IP3v8vJqavUp5B0oOzj6LG/H28D/deFDPma4ukxYN933EN3jWEdDAPnJYHnAnicrW6X037PjLCDDfCFSI0Ag7uERGhacn0+jjtD8HlUp1Rx1vmwGbMVnhwbZaTHb1579ASAEE+s06LC21zzaAovhaQbe+zQpSMyUijBU7QuiOT93DHZjRsxmZe5RUU8DIQ55hYj70k3iiVkN7QKss700e6dtfctedZxSThXIjFLWgv/8PAQNVsIzpb/T9EbqiibvsWDWGn30pVjDsGLltOM8+iakOwaY5/0lO5DEfLUuChV1d2CZpzvH8QHD8iG2ur4i4JJyJ953yzvKO5ewFsOFKupHAR1QyTMYGyd+wtBLsiRYw7IJgsvkF7Z3XUzuwoVhnsDReF9jH2IG6R1rH0CuOAMspnD+PravAeFCSOJY2XVN0eJZmSNZFh77U8mIHTooJSCwBJDzgxT3RrRs23mUrvLm3IDPvN9QHI/tK1YaTGDwQkc9ToO5H5jQwvz90zH0ovu64QtGVVlBqQ0ImoBIs1trB4cPsLKTQwCNKrSPbbeUq80p92o1kVLVC5IWMma6WIwI1t/8YGRdEDhHtxtI81LevAqTKoiA0/YxKk7fHeYb0Icl+v7VFTcWOluoM7E3In9mvRnnXXW3yUlT1/OquygQxkJ75xXPQXRHAjE5m5lMNePySNZ5HGdwvfJjUMH5hRkiMlIcTz2uLNXWo04DCAksS45frCDdsLGik9Djwfii1BQHspudV77QBAWw76StXbeThv8k4JXG/3+pANiUp+AMn9RccVrvcRUuJEyJkRxxlMjFmA8zjfGWRlhd39hotSf1a29SkECiPLbYWO95D3Um1PGVaT4IqNAC/I+Y3Vt+Cu2I60cB1nKIeZosMHjdR1bCrib9DNbT2Pv30p4BnfLYE4hR8WvUpkEgQZRnTYhMQIa9vdMfUo6tEYyvu2xMI8LD22KsgZh+IYQtsfBMtfs9UBXGVBOg6W6BSpCivBUqT+M5PDz3VAB39dB+qaWs1wgkhAN/7/Uqo4DyjheoIYVzChgyX8p/zC9m62ppAhwr4aIrEdtrCsiI1SpBWAeCIKMzXU1FdY96f+EgnJzCD5ViENvkx58HiLUURl4SLYX/YYinVn2m2yS4mIk02S5LEU6tgGjnDdc82KGQLDDQKjU5w9/xz08SIRqwn5PpGeisv3EYoj/9KandHgAU9fDp2qkurm42hGkly4avVs7H58xVrzXW0pP2NW/fJEUOoYqSWZp9bE+Jgr7Y2etBdov2y0kNYaeil4VKsM/m/cIFBs9RmsGmSaBamsj0WMrCuiM9jTDZcj2q0wqvd/yRoIuMnyQ==</ViaThinkSoftSignature> */ ?> |
2 | <?php |
||
3 | |||
4 | /* |
||
5 | * VNag - Nagios Framework for PHP |
||
6 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
7 | * Licensed under the terms of the Apache 2.0 license |
||
8 | * |
||
9 | * Revision 2018-07-15 |
||
10 | */ |
||
11 | |||
12 | declare(ticks=1); |
||
13 | |||
14 | class VNagWebReader extends VNag { |
||
15 | protected $argUrl = null; |
||
16 | protected $argId = null; |
||
17 | protected $argBasicAuth = null; |
||
18 | protected $argPassword = null; |
||
19 | protected $argSignPubKey = null; |
||
20 | |||
21 | public function __construct() { |
||
22 | parent::__construct(); |
||
23 | |||
24 | if ($this->is_http_mode()) { |
||
25 | // Don't allow the standard arguments via $_REQUEST |
||
26 | $this->registerExpectedStandardArguments(''); |
||
27 | } else { |
||
28 | $this->registerExpectedStandardArguments('Vht'); |
||
29 | } |
||
30 | $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)); |
||
31 | $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')); |
||
32 | $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)); |
||
33 | $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)); |
||
34 | $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)); |
||
35 | |||
36 | $this->getHelpManager()->setPluginName('vnag_webreader'); |
||
37 | $this->getHelpManager()->setVersion('1.0'); |
||
38 | $this->getHelpManager()->setShortDescription('This plugin reads embedded machine readable VNag output from a website and converts it into a Nagios compatible output format.'); |
||
39 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
40 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -u <url> [-i <id>] [-b <username>:<password>] [-k pubKeyFile] [-p <password>]'); |
||
41 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
42 | } |
||
43 | |||
44 | protected function cbRun() { |
||
45 | $this->argUrl->require(); |
||
46 | $this->argId->require(); |
||
47 | |||
48 | $url = $this->argUrl->getValue(); |
||
49 | $this->id = $this->argId->getValue(); // default is '0', so we do not need to check for available() |
||
50 | if ($this->argPassword->available()) $this->password_in = $this->argPassword->getValue(); |
||
51 | if ($this->argSignPubKey->available()) $this->pubkey = $this->argSignPubKey->getValue(); |
||
52 | |||
53 | $options = array( |
||
54 | 'http' => array( |
||
55 | 'method' => 'GET', |
||
56 | 'header' => |
||
57 | sprintf("Authorization: Basic %s\r\n", base64_encode($this->argBasicAuth->getValue())). |
||
58 | sprintf("User-Agent: PHP/%s Vag/%s\r\n", phpversion(), self::VNAG_VERSION) |
||
59 | ) |
||
60 | ); |
||
61 | $context = stream_context_create($options); |
||
62 | $cont = file_get_contents($url, false, $context); |
||
63 | if (!$cont) throw new VNagException("Cannot access $url"); |
||
64 | |||
65 | $data = $this->readInvisibleHTML($cont); |
||
66 | |||
67 | if (!$data) throw new VNagInvalidArgumentException("No monitor with ID \"$this->id\" found at URL $url"); |
||
68 | |||
69 | if (isset($data['text'])) { |
||
70 | $this->setHeadline("Special content delivered from the web monitor (see verbose info)"); |
||
71 | $this->addVerboseMessage($data['text'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor |
||
72 | } else { |
||
73 | foreach ($data['performance_data'] as $perfdata) { |
||
74 | $this->addPerformanceData(VNagPerformanceData::createByString($perfdata)); |
||
75 | } |
||
76 | |||
77 | $this->setHeadline($data['headline']); |
||
78 | $this->addVerboseMessage($data['verbose_info'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor |
||
79 | } |
||
80 | |||
81 | $this->setStatus($data['status'], true); |
||
82 | } |
||
83 | } |