1#!/usr/bin/env php 2<?php 3 4/** 5 * Observium 6 * 7 * This file is part of Observium. 8 * 9 * @package observium 10 * @subpackage poller 11 * @author Adam Armstrong <adama@observium.org> 12 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 13 * 14 */ 15 16chdir(dirname($argv[0])); 17 18$options = getopt("h:i:m:n:dqrsV"); 19 20include("includes/sql-config.inc.php"); 21 22include("includes/polling/functions.inc.php"); 23include("html/includes/functions.inc.php"); 24 25$scriptname = basename($argv[0]); 26 27$start = utime(); 28 29if (isset($options['V'])) 30{ 31 print_message(OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION); 32 exit; 33} 34 35if (isset($options['s'])) 36{ 37 // User has asked for spam. LETS MAKE THE SPAM. (sends alerts even if they have already been sent) 38 $spam = TRUE; 39} 40 41if (!isset($options['q'])) 42{ 43 print_cli_banner(); 44} 45 46if ($options['h'] == "all") { $where = " "; $doing = "all"; } 47elseif ($options['h']) 48{ 49 $params = array(); 50 if (is_numeric($options['h'])) 51 { 52 $where = "AND `device_id` = ?"; 53 $doing = $options['h']; 54 $params[] = $options['h']; 55 } 56 else 57 { 58 $where = "AND `hostname` LIKE ?"; 59 $doing = $options['h']; 60 $params[] = str_replace('*','%', $options['h']); 61 } 62} 63 64if (!$where) 65{ 66 print_message("%n 67USAGE: 68$scriptname [-drqV] [-i instances] [-n number] [-m module] [-h device] 69 70EXAMPLE: 71-h <device id> | <device hostname wildcard> Poll single device 72-h odd Poll odd numbered devices (same as -i 2 -n 0) 73-h even Poll even numbered devices (same as -i 2 -n 1) 74-h all Poll all devices 75-h new Poll all devices that have not had a discovery run before 76 77-i <instances> -n <number> Poll as instance <number> of <instances> 78 Instances start at 0. 0-3 for -n 4 79 80OPTIONS: 81 -h Device hostname, id or key odd/even/all/new. 82 -i Poll instance. 83 -n Poll number. 84 -s Sends alerts even if they have already been sent. 85 -q Quiet output. 86 -V Show version and exit. 87 88DEBUGGING OPTIONS: 89 -r Do not create or update RRDs 90 -d Enable debugging output. 91 -dd More verbose debugging output. 92 -m Specify module(s) (separated by commas) to be run. 93 94%rInvalid arguments!%n", 'color'); 95 exit; 96} 97 98print_cli_heading("%WStarting alerter run at ".date("Y-m-d H:i:s"), 0); 99 100$polled_devices = 0; 101 102$alert_rules = cache_alert_rules(); 103$alert_assoc = cache_alert_assoc(); 104 105// Allow the URL building code to build URLs with proper links. 106$_SESSION['userlevel'] = 10; 107 108$query = "SELECT * FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC"; 109foreach (dbFetch($query, $params) as $device) 110{ 111 112 humanize_device($device); 113 114 process_alerts($device); 115 process_notifications(array('device_id' => $device['device_id'])); // Send all notifications (also for syslog from queue) 116 117 dbUpdate(array('last_alerter' => array('NOW()')), 'devices', '`device_id` = ?', array($device['device_id'])); 118 119} 120 121print_cli_heading("%WFinished alerter run at ".date("Y-m-d H:i:s"), 0); 122 123// EOF 124