Subversion Repositories vnag

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 daniel-mar 1
<?php /* <ViaThinkSoftSignature>
2
0EnQNRDWzFcXwaftAzmUPaGYZNHpSmfRPYwDayJPRlOuYDZhpLM2vJaz6bo1nnpkm
3
3KNtIWATaSPJrVk02QBZhNHdk7lbB2O0+kjLIy19o7AcCRxDgQY9CZ5ZicZwYkLwz
4
8Bbs12z4c5wHuYFBe0w9eJeTGwAzzyNT6jF0B9dSV5x/ncml6zH6WXXUjCZWZYDLW
5
mP5ICHID9hMtqYIEguMH6Rb19TELhI0ufjdTIQ444Dw8Z5en43mRSCFMkMKCb5+Uy
6
eOcYz0Nr1zdOH51/B5Qi/Fr2STkq9IRSP+Vx5qel1pr/NYwkRNmEJrClNKI2t2Rrk
7
VzPy21SXYdiwu47YFpSv4TmSuO3VDhmN7E/FMgmivPotJRVO3F0MIQX16zaTF/Mol
8
CxM7kyGORIM1blQNWLmWitLMXeNPT5G85QbPkIcDI92GYsbEqfWQMlEiiIQUFwp5/
9
2Cy1l+2wQgimEpYB7CR4ht8CehaMp+9tCNRnRvfXwlKGGnR+cBdGNg4wFelXmZ6On
10
mjr/CWR7mmxb7nootF9ZDhFmj4pfi2GZstXjVX9xySJGgGXL2HXHPyiakukQ5Vf+3
11
uoVNLOUBSWohFlxvzO7YnNjIddq3jLbDR0q51wnMwJKJSbzQ2ug1uxDqGVLN6Z16U
12
S3NWHweKCpG97U6PJxyL0HQCZkT/0gY/I4DUXgjeRmDaCmpHXg6D3b9jbYa9X31aL
13
7wdcMRNi+kGSqiwrMxD4DYEHHTr1ZBzBjIfj7WKzkkyNlt+lwI461e84e1zlUohZx
14
EiCryYB8C6/cQsaVnC6a4usahjz56dbF7jfF1G06UgFMPNE89KOg2HFdRp3V49+qy
15
fTdAI1A1ZDvJK07XJL+3GfCzpnlHI/XFKbdhkEK4eBH2Q9h0o8ym1HG2yje7i1bNs
16
LQTuCVrzyK2941ZXUSCC8TQUiom2psAA2hWf3lyzFnxK72XoKy4uqEGQRs9exvv8G
17
4sBZpuRLy1XMxFj16dic9S6EDGDNS2RAeNs+gpOlgpxnLIPJ8BHNyTqK4qysquZvw
18
HuXtqWBJ57Kbg4XlsGvFDVFoZoy9I8voGW9Y8e4t0Tw64CB2llJFkKfneWHdxDNXr
19
fNRZVT//e2yGiemaofodJY0PAOFSRYGd3Eh4d2+0qVRPA3jWo4ohSSpaDnJzKXGJo
20
LqJPstcT4bimrQ1WrHrZTHs39puT4jZfSjccTP/qa8ZqiDSqnHhy7U91p47zl8R9M
21
R2uYp09+b8fYq4OnkU7Vgi2XEoL+cbQ4hl5V9Gp3yjnvbHsw1hYMwA+2zziNncw6P
22
63BQcw6p183zK9WKcEBlD5kDrcK3BgFJQf7UlRzFbXfiUOU3BfNWuPbgxFjpSbiT4
23
g==
24
</ViaThinkSoftSignature> */ ?>
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
 *
32
 * Revision 2022-01-12
33
 */
34
 
35
declare(ticks=1);
36
 
37
class VNagAastra430VoiceMail extends VNag {
38
        protected $argFtpHostname = null;
39
        protected $argFtpUsername = null;
40
        protected $argFtpPassword = null;
41
 
42
        const DEFAULT_USERNAME = 'admin';
43
        const DEFAULT_PASSWORD = '33aastra'; // https://productdocuments.mitel.com/doc_finder/DocFinder/syd-0343_de.pdf?get&DNR=syd-0343?get&DNR=syd-0343 , Page 178
44
 
45
        public function __construct() {
46
                parent::__construct();
47
 
48
                if ($this->is_http_mode()) {
49
                        // Don't allow the standard arguments via $_REQUEST
50
                        $this->registerExpectedStandardArguments('');
51
                } else {
52
                        $this->registerExpectedStandardArguments('Vht');
53
                }
54
                $this->addExpectedArgument($this->argFtpHostname = new VNagArgument('H', 'ftphostname', VNagArgument::VALUE_REQUIRED, 'ftphostname', 'The FTP hostname', null));
55
                $this->addExpectedArgument($this->argFtpUsername = new VNagArgument('u', 'ftpusername', VNagArgument::VALUE_REQUIRED, 'ftpusername', 'The FTP username (usually "'.self::DEFAULT_USERNAME.'")', self::DEFAULT_USERNAME));
56
                $this->addExpectedArgument($this->argFtpPassword = new VNagArgument('p', 'ftppassword', VNagArgument::VALUE_REQUIRED, 'ftppassword', 'The FTP password (default "'.self::DEFAULT_PASSWORD.'")', self::DEFAULT_PASSWORD));
57
 
58
                $this->getHelpManager()->setPluginName('vnag_aastra_430_voicemail');
59
                $this->getHelpManager()->setVersion('1.0');
60
                $this->getHelpManager()->setShortDescription('This plugin checks for voicemail messages on a Aastra 430.');
61
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
62
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -H <ftphost> -u <ftpusername> -p <ftppassword>');
63
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
64
        }
65
 
66
        protected static function aastra430NumVm($ftp_host, $user, $password) {
67
                if (!($conn = @ftp_connect($ftp_host))) throw new Exception('FTP Connect failed');
68
                if (!@ftp_login($conn, $user, $password)) throw new Exception('FTP Login failed');
69
 
70
                // TODO: Only count vm*.dat
71
                // TODO: Also check timestamp of oldest and newest message!
72
 
73
                $messages = @ftp_nlist($conn, '/home/voice/vm/gen'); // the files are named vm*.dat
74
                if (!is_array($messages)) throw new Exception('FTP Ordner nicht gefunden');
75
                $count = count($messages);
76
                @ftp_close($conn);
77
                return $count;
78
        }
79
 
80
        protected function cbRun() {
81
                $this->argFtpHostname->require();
82
                // $this->argFtpUsername->require();
83
                // $this->argFtpPassword->require();
84
 
85
                $ftp_hostname = $this->argFtpHostname->getValue();
86
                $ftp_username = $this->argFtpUsername->getValue();
87
                $ftp_password = $this->argFtpPassword->getValue();
88
 
89
                $count = self::aastra430NumVm($ftp_hostname, $ftp_username, $ftp_password);
90
 
91
                $this->setStatus("$count new voicemail messsages", true);
92
                if ($count == 0) {
93
                        $this->setStatus(VNag::STATUS_OK);
94
                } else {
95
                        $this->setStatus(VNag::STATUS_WARNING);
96
                }
97
        }
98
}