## Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
##
## 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
##
## 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
## GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
VERSION="0.01"
from operator import truediv
import os
import re
import subprocess
import json
from sys import stderr
nc_config = {
"nextcloud.zmb.rocks": {
"nc_php_version": "8.0",
"nc_www_user": "www-data",
"nc_path": "/var/www/nextcloud"
}
}
def check_nextcloud(name:str, conf:dict):
printout(name,"Status", status(conf))
printout(name,"Updates", update_check(conf))
def update_check(conf:dict):
result = occ("update:check", conf['nc_www_user'],conf['nc_path'], conf['nc_php_version'])
updates = "Updates:\n" + "\n".join(map(lambda x: "{0}:{1}".format(*x),re.findall("(\w+)(?:\sto version)?\s([\d+.]+) is available",result)))
count = result.split('\n')[-2].split(' ')[0]
else:
updates = result
count = 0
return f" updates={count};;1 {updates}"
def status(conf:dict):
result = json.loads(occ("status", conf['nc_www_user'],conf['nc_path'], conf['nc_php_version'], output="json"))
if result.get('installed') == False:
state = 2
elif ('maintenance' in result.keys() and result.get('maintenance') == True) or ('needsDbUpgrade' in result.keys() and result.get('needsDbUpgrade') == True):
print (f'2 "{name}" Dependency failed: php{conf["nc_php_version"]} - Please check if php version is configured correctly in /etc/checkmk/nextcloud.conf')