Rev 76 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
34 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
77 | daniel-mar | 2 | myqtvoBJksxWOcps08w5hHhtw63ugrOY7d+PtnrZa0wOCYBwaFW2ngbvBzF4lJShC |
3 | +/zx5NJWtn/0oAjHyhti/r6wSpOetg3gbJuh0mFq2YPyFhZ3DKS61XU711FNl8U1i |
||
4 | RJah0DsEBppzATh6/SjnORteRwNP3TcVQ+0WFugA1OzjMNmn8ThYcFevH6PS3ICYB |
||
5 | ydTDgJOVZVVlQWNQ5Xire7s1/if9z+hM9MhYVgmE2JR7lVKo+97KvcBg37npHezp5 |
||
6 | 6Zs7tVgf7mVViO1pk1X0nvJdk1db0UXcxidu2+evfg7nsgUgraKqToxlrNsST41lv |
||
7 | lPyOjeb9c8z788yKzTfQ6M0s1ECbkM1q8sGLjWRl1nfQwxqnLJMchJbH9iGkDL9aF |
||
8 | IVPH5zo288Ta0YAy3rZTJ/KJHJ/riQVbRUPyOIWtpeC32n9YYSUh5r6G3zNrIi6Dj |
||
9 | p0l0tQJ3VlBLqrReHD5xY5BiMqm9cyFFkyozsZ5qMhQ22oexvnIlvj2et40r/OMbN |
||
10 | LJXOrapmkPkXeuF5ZiVlUcBMQt+uDlceCQMeLTQmtCOKgaml/ljTKGSM9byoUJQ1O |
||
11 | qBKnJoAr+/wH07Xy116ZPt/u5iXDJyYiIyGVWMYfnj94zrvWmh7wab1S6uicvbnu3 |
||
12 | 7w6hhyeTGQ/MxCseQEpNGNzYo1pL/6fCCBllPaTXLWVwbKnxWHo65Y4KyDkzdjJjU |
||
13 | XA6uF8Wv+vGtpQBWG8F/jH+DFHOR9Dl3MLaSNIPVuFgCZ4YPPIfZoEiLXrjCaWI3T |
||
14 | ZDBND6urBUqNWMXUSEUKmpRJoq1iBa8JF5zysl2sVck/L6uzohR9aMUZtxJkqTnHh |
||
15 | KSbBm2w2NOzOqan1Gl+NR0awFeCQf2taS+vkbZmSpeLMMMi7921+hVTEzgtmTC5IP |
||
16 | OKBu6ajOw25Tdaqd9YZffCJtXl5IJM9U72SHBrSKC/lt6zTaG+lk3jdy4O140TR1D |
||
17 | vN1WpoPXuYw+IoI442U9uzD97/qLzkgvg2jwJWvQcVSGBCkdOj5y61ZEt/1VIHp0Z |
||
18 | zKO6dIZAZQ7fCw5samLaAjAVzDzEFevI05pHZdyzXUf8Oh7DndCxMSrkgyjvid/X3 |
||
19 | SXAsImdKeWl35NonLmBhnpzufU0/cs6XsdWlZUD5qWoXlMRJMXSyj76ol4Lt+gAKG |
||
20 | L5auTP8WAc2e+fYi8PuXXZf2bpoekQ4yu7Ynh9h5kWfbg1G4+04w9bVW2v1M0mWUk |
||
21 | PaxIlL5KgjcO4BBbEKIoTYNXZIV4kBhnVWmxIv0L4r5NPzNaMRl6iIzWtehk2tWV2 |
||
22 | 0MsvwOFIfL+OvtPGqZ8Lrfu7prFvozyVWioSSGfMMmGrPiwmS/7a5qvV3aazpNEBp |
||
23 | w== |
||
34 | daniel-mar | 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 | * |
||
76 | daniel-mar | 32 | * Revision 2023-10-13 |
34 | daniel-mar | 33 | */ |
34 | |||
35 | declare(ticks=1); |
||
36 | |||
37 | class GitLabVersionCheck extends VNag { |
||
38 | protected $argSystemDir = null; |
||
39 | |||
40 | public function __construct() { |
||
41 | parent::__construct(); |
||
42 | |||
43 | $this->registerExpectedStandardArguments('Vvht'); |
||
44 | |||
45 | $this->getHelpManager()->setPluginName('check_gitlab_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local GitLab system has the latest version installed.'); |
||
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
||
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
51 | |||
52 | // Individual (non-standard) arguments: |
||
53 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'gitLabPath', 'The local directory where your GitLab installation (version-manifest.txt) is located.')); |
||
54 | } |
||
55 | |||
56 | protected function getInstalledVersion($dir) { |
||
57 | $version_manifest = $dir.'/version-manifest.json'; |
||
58 | |||
59 | if (!file_exists($version_manifest)) { |
||
77 | daniel-mar | 60 | throw new VNagException('This is not a valid GitLab installation in "'.$dir.'" (version-manifest.json is missing).'); |
34 | daniel-mar | 61 | } |
62 | |||
77 | daniel-mar | 63 | $cont = @file_get_contents($version_manifest); |
64 | if ($cont === false) { |
||
65 | throw new VNagException('Cannot read version-manifest.json from GitLab installation in "'.$dir.'".'); |
||
66 | } |
||
67 | $json = @json_decode($cont,true); |
||
68 | if ($json === false) { |
||
69 | throw new VNagException('This is not a valid GitLab installation in "'.$dir.'" (version-manifest.json has invalid JSON data).'); |
||
70 | } |
||
71 | |||
34 | daniel-mar | 72 | return $json['build_version']; |
73 | } |
||
74 | |||
75 | protected function getServerResponse($version) { |
||
76 | $opts = array( |
||
77 | 'http'=>array( |
||
78 | 'method'=>"GET", |
||
76 | daniel-mar | 79 | 'header'=>"Referer: http://example.org/\r\n" // Important!!! |
34 | daniel-mar | 80 | ) |
81 | ); |
||
82 | $context = stream_context_create($opts); |
||
83 | $url = "https://version.gitlab.com/check.svg?gitlab_info=". |
||
84 | urlencode(base64_encode('{"version":"'.$version.'"}')); |
||
76 | daniel-mar | 85 | $cont = $this->url_get_contents($url, 1*60*60, $context); |
34 | daniel-mar | 86 | |
76 | daniel-mar | 87 | if ($cont === false) { |
77 | daniel-mar | 88 | throw new VNagException('Cannot query version.gitlab.com for version check (Version '.$version.')'); |
34 | daniel-mar | 89 | } |
90 | |||
76 | daniel-mar | 91 | if (!preg_match('@>([^<]+)</text>@ismU', $cont, $m)) { |
77 | daniel-mar | 92 | throw new VNagException('Server version.gitlab.com sent an unexpected reply (Version '.$version.')'); |
34 | daniel-mar | 93 | } |
94 | |||
95 | return $m[1]; |
||
96 | } |
||
97 | |||
98 | protected function cbRun($optional_args=array()) { |
||
99 | $system_dir = $this->argSystemDir->getValue(); |
||
100 | if (empty($system_dir)) { |
||
77 | daniel-mar | 101 | throw new VNagException("Please specify the directory of the GitLab installation."); |
34 | daniel-mar | 102 | } |
103 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
104 | |||
105 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 106 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
34 | daniel-mar | 107 | } |
108 | |||
109 | $cur_ver = $this->getInstalledVersion($system_dir); |
||
110 | $status = $this->getServerResponse($cur_ver); |
||
111 | |||
112 | if ($status == 'up-to-date') { |
||
113 | $this->setStatus(VNag::STATUS_OK); |
||
114 | } else if ($status == 'update available') { |
||
115 | $this->setStatus(VNag::STATUS_WARNING); |
||
35 | daniel-mar | 116 | } else if ($status == 'update asap') { |
117 | $this->setStatus(VNag::STATUS_CRITICAL); |
||
34 | daniel-mar | 118 | } else { |
119 | $this->setStatus(VNag::STATUS_UNKNOWN); |
||
120 | } |
||
35 | daniel-mar | 121 | $this->setHeadline("GitLab currently installed version $cur_ver [$status] at $system_dir", true); |
34 | daniel-mar | 122 | } |
123 | } |