. * * @package LibreNMS * @link http://librenms.org * @copyright 2020 Thomas Berberich * @author Thomas Berberich */ namespace LibreNMS\Validations; use LibreNMS\Config; use LibreNMS\Util\Version; use LibreNMS\Validator; use Symfony\Component\Process\Process; class Python extends BaseValidation { const PYTHON_MIN_VERSION = '3.4.0'; /** * Validate this module. * To return ValidationResults, call ok, warn, fail, or result methods on the $validator * * @param Validator $validator */ public function validate(Validator $validator) { $version = Version::python(); if (empty($version)) { $validator->fail('python3 not found', 'Install Python 3 for your system.'); return; // no need to check anything else } $this->checkVersion($validator, $version); $this->checkExtensions($validator); } private function checkVersion(Validator $validator, $version) { if (version_compare($version, self::PYTHON_MIN_VERSION, '<')) { $validator->warn("Python version $version too old.", 'Python version ' . self::PYTHON_MIN_VERSION . ' is the minimum supported version. We recommend you update Python to a supported version.'); } } private function checkExtensions(Validator $validator) { $user = Config::get('user', 'librenms'); if (get_current_user() !== $user) { $validator->warn("Could not check Python dependencies because this script is not running as $user"); return; } $pythonExtensions = '/scripts/check_requirements.py'; $process = new Process([Config::get('install_dir') . $pythonExtensions, '-v']); $process->run(); if ($process->getExitCode() !== 0) { $validator->fail("Python3 module issue found: '" . $process->getOutput() . "'", 'pip3 install -r requirements.txt'); } } }