Rev 77 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
44 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * VNag - Nagios Framework for PHP |
||
5 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
6 | * Licensed under the terms of the Apache 2.0 license |
||
7 | * |
||
77 | daniel-mar | 8 | * Revision 2023-10-13 |
44 | daniel-mar | 9 | */ |
10 | |||
11 | declare(ticks=1); |
||
12 | |||
13 | class VNagAastra430VoiceMail extends VNag { |
||
14 | protected $argFtpHostname = null; |
||
15 | protected $argFtpUsername = null; |
||
16 | protected $argFtpPassword = null; |
||
17 | |||
18 | const DEFAULT_USERNAME = 'admin'; |
||
19 | 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 |
||
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->argFtpHostname = new VNagArgument('H', 'ftphostname', VNagArgument::VALUE_REQUIRED, 'ftphostname', 'The FTP hostname', null)); |
||
31 | $this->addExpectedArgument($this->argFtpUsername = new VNagArgument('u', 'ftpusername', VNagArgument::VALUE_REQUIRED, 'ftpusername', 'The FTP username (usually "'.self::DEFAULT_USERNAME.'")', self::DEFAULT_USERNAME)); |
||
32 | $this->addExpectedArgument($this->argFtpPassword = new VNagArgument('p', 'ftppassword', VNagArgument::VALUE_REQUIRED, 'ftppassword', 'The FTP password (default "'.self::DEFAULT_PASSWORD.'")', self::DEFAULT_PASSWORD)); |
||
33 | |||
34 | $this->getHelpManager()->setPluginName('vnag_aastra_430_voicemail'); |
||
79 | daniel-mar | 35 | $this->getHelpManager()->setVersion('2023-10-13'); |
44 | daniel-mar | 36 | $this->getHelpManager()->setShortDescription('This plugin checks for voicemail messages on a Aastra 430.'); |
37 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
38 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -H <ftphost> -u <ftpusername> -p <ftppassword>'); |
||
39 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
40 | } |
||
41 | |||
42 | protected static function aastra430NumVm($ftp_host, $user, $password) { |
||
77 | daniel-mar | 43 | if (!($conn = @ftp_connect($ftp_host))) throw new VNagException('FTP connect failed'); |
44 | if (!@ftp_login($conn, $user, $password)) throw new VNagException('FTP login failed'); |
||
44 | daniel-mar | 45 | |
46 | // TODO: Only count vm*.dat |
||
47 | // TODO: Also check timestamp of oldest and newest message! |
||
48 | |||
49 | $messages = @ftp_nlist($conn, '/home/voice/vm/gen'); // the files are named vm*.dat |
||
77 | daniel-mar | 50 | if (!is_array($messages)) throw new VNagException('FTP folder not found!'); |
44 | daniel-mar | 51 | $count = count($messages); |
52 | @ftp_close($conn); |
||
53 | return $count; |
||
54 | } |
||
55 | |||
56 | protected function cbRun() { |
||
57 | $this->argFtpHostname->require(); |
||
58 | // $this->argFtpUsername->require(); |
||
59 | // $this->argFtpPassword->require(); |
||
60 | |||
61 | $ftp_hostname = $this->argFtpHostname->getValue(); |
||
62 | $ftp_username = $this->argFtpUsername->getValue(); |
||
63 | $ftp_password = $this->argFtpPassword->getValue(); |
||
64 | |||
65 | $count = self::aastra430NumVm($ftp_hostname, $ftp_username, $ftp_password); |
||
66 | |||
67 | $this->setStatus("$count new voicemail messsages", true); |
||
68 | if ($count == 0) { |
||
69 | $this->setStatus(VNag::STATUS_OK); |
||
70 | } else { |
||
71 | $this->setStatus(VNag::STATUS_WARNING); |
||
72 | } |
||
73 | } |
||
46 | daniel-mar | 74 | } |