Init Repo
This commit is contained in:
50
resources/templates/coretemp_monitoring.tmp.php
Normal file
50
resources/templates/coretemp_monitoring.tmp.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'cron/cron.class.php') or die('Error: 0x0003');
|
||||
(include_once LIBRARY_PATH.'curl/curl.class.php') or die('Error: 0x0004');
|
||||
|
||||
$cron = new Cron;
|
||||
$cron->setName('coretemp_monitoring');
|
||||
|
||||
$coreTemp = rpi_getCoreTemprature();
|
||||
|
||||
if ($cron->isExists() === true && $coreTemp > getConfig('main:monitoringCpuTemp.maximum', 60))
|
||||
{
|
||||
$ifOption = false;
|
||||
|
||||
if ((getConfig('cron:execution.monitoringCpuTemp', 0)+3600) <= time())
|
||||
{
|
||||
if (getConfig('main:monitoringCpuTemp.emailEnabled', 'false') == 'true' && getConfig('main:monitoringCpuTemp.email', '') != '' && getConfig('main:monitoringCpuTemp.code', '') != '' && getConfig('main:monitoringCpuTemp.id', '') != '')
|
||||
{
|
||||
$curl = new cURL($config['url']['temperatureMonitoring'], HTTP_POST);
|
||||
$curl->addParameter(array('type' => 'send'));
|
||||
$curl->addParameter(array('id' => getConfig('main:monitoringCpuTemp.id', '')));
|
||||
$curl->addParameter(array('code' => getConfig('main:monitoringCpuTemp.code', '')));
|
||||
$curl->addParameter(array('email' => getConfig('main:monitoringCpuTemp.email', '')));
|
||||
$curl->addParameter(array('label' => getConfig('main:main.label', 'Raspberry Pi')));
|
||||
$curl->addParameter(array('maximum' => getConfig('main:monitoringCpuTemp.maximum', 60)));
|
||||
$curl->addParameter(array('coretemp' => $coreTemp));
|
||||
$curl->addParameter(array('lang' => $globalLanguage));
|
||||
$curl->execute();
|
||||
|
||||
if ($curl->getStatusCode() == 200)
|
||||
$ifOption = true;
|
||||
}
|
||||
|
||||
if (getConfig('main:monitoringCpuTemp.shellEnabled', 'false') == 'true' && getConfig('main:monitoringCpuTemp.shell', '') != '')
|
||||
{
|
||||
shell_exec(base64_decode(getConfig('main:monitoringCpuTemp.shell', '')));
|
||||
$ifOption = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ifOption === true)
|
||||
setConfig('cron:execution.monitoringCpuTemp', time());
|
||||
}
|
||||
?>
|
||||
110
resources/templates/notification.tmp.php
Normal file
110
resources/templates/notification.tmp.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'main/rpi.function.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'curl/curl.class.php') or die('Error: 0x0003');
|
||||
|
||||
if (getConfig('main:notificationPB.enabled', false))
|
||||
{
|
||||
$token = getConfig('main:notificationPB.token', '');
|
||||
$lastPush = json_decode(htmlspecialchars_decode(getConfig('main:notificationPB.lastPush', '{}')), true);
|
||||
|
||||
if (getConfig('main:notificationPB.picontrolVersionEnabled', 'false') == 'true' && (getConfig('cron:updateCheck.picontrol', 0)+21600) < time())
|
||||
{
|
||||
$picontrolUpdate = checkUpdate();
|
||||
|
||||
if (!isset($lastPush['picontrol']))
|
||||
$lastPush['picontrol'] = array('time' => 0, 'value' => 0, 'notification_iden' => '');
|
||||
|
||||
if (!is_array($picontrolUpdate))
|
||||
setConfig('cron:updateCheck.picontrol', time());
|
||||
else
|
||||
{
|
||||
if ($lastPush['picontrol']['value'] < $picontrolUpdate['versioncode'] && $lastPush['picontrol']['time']+21600 < time())
|
||||
{
|
||||
setConfig('cron:updateCheck.picontrol', time()-86400);
|
||||
|
||||
$curl = new cURL('https://api.pushbullet.com/v2/pushes', HTTP_POST);
|
||||
$curl->addHeader(array('Authorization: Bearer '.$token, 'Content-Type: application/json'));
|
||||
$curl->setParameterRaw(json_encode(array('type' => 'note', 'title' => 'Pi Control | '._t('Aktualisierung verfügbar'), 'body' => _t('Pi Control Version %s steht ab sofort für dein Pi Control "%s" zum herunterladen bereit.', $picontrolUpdate['version'], getConfig('main:main.label', 'Raspberry Pi')))));
|
||||
$curl->execute();
|
||||
|
||||
// Reduziere Traffic, da selbst bei Fehler erst wieder nach 21600 Sek. geprüft wird
|
||||
$lastPush['picontrol']['time'] = time();
|
||||
|
||||
if ($curl->getResult($data) == JSON_ERROR_NONE)
|
||||
{
|
||||
if (!isset($data['error']))
|
||||
{
|
||||
$lastPush['picontrol']['value'] = $picontrolUpdate['versioncode'];
|
||||
$lastPush['picontrol']['notification_iden'] = $return['iden'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getConfig('main:notificationPB.cpuTemperatureEnabled', 'false') == 'true')
|
||||
{
|
||||
$temp = rpi_getCoreTemprature();
|
||||
|
||||
if (!isset($lastPush['cpu_temp']))
|
||||
$lastPush['cpu_temp'] = array('time' => 0, 'value' => 0, 'notification_iden' => '');
|
||||
|
||||
if ($temp > getConfig('main:notificationPB.cpuTemperatureMaximum', 65) && $lastPush['cpu_temp']['value'] < ($temp + 5) && $lastPush['cpu_temp']['time']+300 < time())
|
||||
{
|
||||
$curl = new cURL('https://api.pushbullet.com/v2/pushes', HTTP_POST);
|
||||
$curl->addHeader(array('Authorization: Bearer '.$token, 'Content-Type: application/json'));
|
||||
$curl->setParameterRaw(json_encode(array('type' => 'note', 'title' => 'Pi Control | '._t('Temperaturüberschreitung'), 'body' => _t('Dein Pi Control "%s" meldet eine erhöhte Temperatur der CPU von %s °C.', getConfig('main:main.label', 'Raspberry Pi'), $temp))));
|
||||
$curl->execute();
|
||||
|
||||
if ($curl->getResult($data) == JSON_ERROR_NONE)
|
||||
{
|
||||
if (!isset($data['error']))
|
||||
{
|
||||
$lastPush['cpu_temp']['time'] = time();
|
||||
$lastPush['cpu_temp']['value'] = $temp;
|
||||
$lastPush['cpu_temp']['notification_iden'] = $data['iden'];
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (getConfig('main:notificationPB.cpuTemperatureMaximum', 65) > $temp)
|
||||
$lastPush['cpu_temp']['value'] = 0;
|
||||
}
|
||||
|
||||
if (getConfig('main:notificationPB.memoryUsedEnabled', 'false') == 'true')
|
||||
{
|
||||
$memory = rpi_getMemoryInfo();
|
||||
$percent = $memory[count($memory)-1]['percent'];
|
||||
|
||||
if (!isset($lastPush['memory']))
|
||||
$lastPush['memory'] = array('time' => 0, 'value' => 0, 'notification_iden' => '');
|
||||
|
||||
if (getConfig('main:notificationPB.memoryUsedLimit', 80) < $percent && $lastPush['memory']['value'] < ((100 - $percent) / 10 + $percent) && $lastPush['memory']['time']+3600 < time())
|
||||
{
|
||||
$curl = new cURL('https://api.pushbullet.com/v2/pushes', HTTP_POST);
|
||||
$curl->addHeader(array('Authorization: Bearer '.$token, 'Content-Type: application/json'));
|
||||
$curl->setParameterRaw(json_encode(array('type' => 'note', 'title' => 'Pi Control | '._t('Speicherverbrauch'), 'body' => _t('Dein Pi Control "%s" meldet einen Speicherverbrauch von %d%%.', getConfig('main:main.label', 'Raspberry Pi'), $percent))));
|
||||
$curl->execute();
|
||||
|
||||
if ($curl->getResult($data) == JSON_ERROR_NONE)
|
||||
{
|
||||
if (!isset($data['error']))
|
||||
{
|
||||
$lastPush['memory']['time'] = time();
|
||||
$lastPush['memory']['value'] = $percent;
|
||||
$lastPush['memory']['notification_iden'] = $data['iden'];
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (getConfig('main:notificationPB.memoryUsedLimit', 80) > $percent)
|
||||
$lastPush['memory']['value'] = 0;
|
||||
}
|
||||
|
||||
setConfig('main:notificationPB.lastPush', htmlspecialchars(json_encode($lastPush)));
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user