Subversion Repositories vnag

Rev

Rev 54 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 daniel-mar 1
<?php /* <ViaThinkSoftSignature>
70 daniel-mar 2
Q5Qtv/JGX2tdxoEqxXuF2TaMaX26SuclN68wP5pYOwMe01/GepIHEZNJU6vFf1JO/
3
Fu/OZ99tRamEa1ckOEdCR9R/oiadNqQ/3U56/qV0/9NMbVcaETamUFImUm3ztpvFN
4
83t5S0DtVqqVfCQ08UpJCUTsgFbztlOILKK2yfyIPzwK0vQFAza98fRCZfidJTxYm
5
xPuThlzLFoVlxyczR5OiCKdwJm1UzZhRCToIbLMU6dIwkx8mE0CBGYcR1sUVBeRoT
6
Wjqcz4JN7lGNihUYirTZL7kNTllu6lcGIUIQtDGwLw8vYEeUr3XoGvUKZwQtqd6Yn
7
7/Bw9UmDU2/lNHdMtSgzMRVa7m8hXSApdjKxzzvnoK1qU4bBxaiiCAUSBq1K9hfRf
8
9oRx5Kea3Jl/uV7aAsr5MMO45CYUxCwPMS/KykTXMAtOe9Yr53GAciQZbxTKCen6G
9
Wh1wxImMEoFc2m1axWMqzmvsNJw7ZGODbYGgY351htsVhgTdZLxPJOGt5dLs9zsQA
10
b9/+lMyejv/ZVZ5zOLpfIilbAOZaTSh834YNY2PciKIoPsg/umIYPx2ELcsmgtOrN
11
nIjvvGBK3r18QBJUN3y9SlEwm9ej62hU/PvQ1HiG+iqtoE86BzxhcUkDn6WUXOlaa
12
fB4BgETjG+RwX9Kj+h2ZTTiKqoPN1BlpxlUKrQ9ZTLdpy3PHdkA35N2EEFPcCVdf3
13
ada6oDhmPhvhXbcFZ29Ip100I1L4lxHJcU5XCHJzEaMLkIX5nyT1tPZL1XnV5fOyH
14
l/LxR/H+t5cvDw4ybqPj11XshtQvxGxkLDyMB2ZUU0mpiUJyxePdAXXPPmOpdO37I
15
MCStMGQxqrvIJL/EdQn8BVQuDBKm53lXNMGlt1tEky6w8ikTYd+HfSbt/S3yWQATn
16
elVfQfyEB4+GR/bckylsoirQQpiFZONMIV+iCEE7QUFdM7ms933hRP4Pg9rISaP3i
17
t7jk7v4Ad1AF9JQLP64cyQdHJaaR97nLYtSYp7WVj9VEMb8WdB21wjBecsJktqdTv
18
E/gj8a3X71bheeSMc9ZS4sBGhkTryhEb3R4i6yLyyrCJxc3P2ZSvEvkj7OKmHhlWA
19
nKBhH0Ka4Acv82FFu34hcwksCVf1otQlfAP867EoKRTN9Z5gq0ljpj6Qya0OFuXsV
20
PVs2h4B4qXqxWD301tYkP6YChHTGLXmo3LAje1OgqOIrivuP7hvZ4v8awaLn/xIFc
21
REMolTxoQTw+C7F5NmUyy6/1WgpFCQzKcMGxZu+A/xG0G8SwhY5+tlMtWMGUWupyG
22
RTb901U+uuLs7trE2qxfOq567wmYLdXhU70RKxq1yrGopr2CTGK/g0So3+MqRHNkv
23
w==
4 daniel-mar 24
</ViaThinkSoftSignature> */ ?>
2 daniel-mar 25
<?php
26
 
27
/*
28
 * VNag - Nagios Framework for PHP
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
30
 * Licensed under the terms of the Apache 2.0 license
31
 *
70 daniel-mar 32
 * Revision 2023-09-13
2 daniel-mar 33
 */
34
 
35
declare(ticks=1);
36
 
37
class VNagWebReader extends VNag {
38
        protected $argUrl = null;
39
        protected $argId = null;
40
        protected $argBasicAuth = null;
41
        protected $argPassword = null;
42
        protected $argSignPubKey = null;
43
 
44
        public function __construct() {
45
                parent::__construct();
46
 
47
                if ($this->is_http_mode()) {
48
                        // Don't allow the standard arguments via $_REQUEST
49
                        $this->registerExpectedStandardArguments('');
50
                } else {
51
                        $this->registerExpectedStandardArguments('Vht');
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));
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));
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));
58
 
59
                $this->getHelpManager()->setPluginName('vnag_webreader');
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.');
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>]');
64
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
65
        }
66
 
67
        protected function cbRun() {
68
                $this->argUrl->require();
69
                $this->argId->require();
70
 
71
                $url = $this->argUrl->getValue();
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();
74
                if ($this->argSignPubKey->available()) $this->pubkey = $this->argSignPubKey->getValue();
75
 
70 daniel-mar 76
                $header = '';
77
                $auth = $this->argBasicAuth->getValue();
78
                if (!is_null($auth)) $auth .= sprintf("Authorization: Basic %s\r\n", base64_encode($auth));
79
                $header .= sprintf("User-Agent: PHP/%s VNag/%s\r\n", phpversion(), self::VNAG_VERSION);
80
 
2 daniel-mar 81
                $options = array(
82
                    'http' => array(
83
                        'method' => 'GET',
70 daniel-mar 84
                        'header' => $header
2 daniel-mar 85
                    )
86
                );
87
                $context = stream_context_create($options);
88
                $cont = file_get_contents($url, false, $context);
89
                if (!$cont) throw new VNagException("Cannot access $url");
90
 
91
                $data = $this->readInvisibleHTML($cont);
92
 
93
                if (!$data) throw new VNagInvalidArgumentException("No monitor with ID \"$this->id\" found at URL $url");
94
 
95
                if (isset($data['text'])) {
96
                        $this->setHeadline("Special content delivered from the web monitor (see verbose info)");
97
                        $this->addVerboseMessage($data['text'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor
98
                } else {
99
                        foreach ($data['performance_data'] as $perfdata) {
100
                                $this->addPerformanceData(VNagPerformanceData::createByString($perfdata));
101
                        }
102
 
103
                        $this->setHeadline($data['headline']);
104
                        $this->addVerboseMessage($data['verbose_info'], VNag::VERBOSITY_SUMMARY); // VERBOSE_SUMMARY is *our* verbosity, not the verbosity of the target monitor
105
                }
106
 
107
                $this->setStatus($data['status'], true);
108
        }
109
}