コード例 #1
0
ファイル: main.php プロジェクト: tibezh/telegram-zabbix
use Monolog\Handler\StreamHandler;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Exception\TelegramException;
use ZabbixApi\ZabbixApi;
$log = new Logger('drudeskbot');
$log->pushHandler(new StreamHandler('logs/app.log', Logger::DEBUG));
// Load settings.
$settings = (require __DIR__ . '/settings.php');
//print $settings;
$COMMANDS_FOLDER = __DIR__ . '/Commands/';
$errors = array();
try {
    // Connect to Zabbix API.
    $api = new ZabbixApi($ZABBIX_HOST . 'api_jsonrpc.php', $ZABBIX_USER, $ZABBIX_PASSWORD);
    $api->setDefaultParams(array('output' => 'extend'));
    $triggers = $api->triggerGet(array('filter' => array('value' => 1)));
    foreach ($triggers as $trigger) {
        $errors[] = $trigger->description;
    }
} catch (Exception $e) {
    // Exception in ZabbixApi catched.
    echo $e->getMessage();
}
try {
    // create Telegram API object
    $telegram = new Telegram($API_KEY, $BOT_NAME);
    $telegram->enableMySQL($credentials);
    $telegram->addCommandsPath($COMMANDS_FOLDER);
    $telegram->setLogRequests(true);
    $telegram->setLogPath('logs/' . $BOT_NAME . '.log');
    $telegram->setLogVerbosity(3);
コード例 #2
0
 //	echo "<div class=\"groupbox\">"; // Again, we dont want to use the groupfunction yet
 //      echo "<div class=\"title\">" . $groupname . "</div>";
 // print all host IDs
 foreach ($hosts as $host) {
     // Check if host is not disabled, we don't want them!
     $flaghost = $host->flags;
     if ($flaghost == "0" && $count == "0") {
         echo "<div class=\"groupbox js-masonry\" data-masonry-options='{ \"itemSelector\": \".hostbox\" }'\">";
         // echo "<div class=\"title\">" . $groupname . "</div>";
         $count++;
     }
     if ($flaghost == "0" && $count != "0") {
         $hostid = $host->hostid;
         $hostname = $host->name;
         $maintenance = $host->maintenance_status;
         $trigger = $api->triggerGet(array('output' => 'extend', 'hostids' => $hostid, 'sortfield' => 'priority', 'sortorder' => 'DESC', 'only_true' => '1', 'active' => '1', 'withUnacknowledgedEvents' => '1'));
         if ($trigger) {
             // Highest Priority error
             $hostboxprio = $trigger[0]->priority;
             //First filter the hosts that are in maintenance and assign the maintenance class if is true
             if ($maintenance != "0") {
                 echo "<div class=\"hostbox maintenance\">";
             } else {
                 echo "<div class=\"hostbox nok" . $hostboxprio . "\">";
             }
             echo "<div class=\"title\">" . $hostname . "</div><div class=\"hostid\">" . $hostid . "</div>";
             $count = "0";
             foreach ($trigger as $event) {
                 if ($count++ <= 2) {
                     $priority = $event->priority;
                     $description = $event->description;