Skip to content

Commit

Permalink
Automation fixes / features
Browse files Browse the repository at this point in the history
Fix various PHP errors
Add options for 20 and 50 threads
(Bumping it to 100 threads finishes a /24 in 8 seconds, but can cause
MySQL connection issues, it does work without error though)
  • Loading branch information
cigamit committed May 28, 2015
1 parent 420ad37 commit f276e3c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
4 changes: 3 additions & 1 deletion automation_networks.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ function network_edit() {
'7' => '7 Threads',
'8' => '8 Threads',
'9' => '9 Threads',
'10' => '10 Threads'
'10' => '10 Threads',
'20' => '20 Threads',
'50' => '50 Threads'
),
'default' => 1
),
Expand Down
3 changes: 2 additions & 1 deletion lib/api_automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3158,7 +3158,7 @@ function automation_primeIPAddressTable($network_id) {
}
}

automation_debug("A Total of $total IP Addressed Primed");
automation_debug("A Total of $total IP Addresses Primed\n");
}

function automation_valid_snmp_device (&$device) {
Expand All @@ -3172,6 +3172,7 @@ function automation_valid_snmp_device (&$device) {
snmp_set_oid_numeric_print(TRUE);
}

$snmp_items = db_fetch_assoc_prepared('SELECT * FROM automation_snmp_items WHERE snmp_id = ? ORDER BY sequence ASC', array($device['snmp_id']));

if (sizeof($snmp_items)) {
foreach($snmp_items as $item) {
Expand Down
36 changes: 19 additions & 17 deletions poller_automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function sig_handler($signo) {
AND task!='tmaster'", array($network_id)), 'pid', 'pid');

if (sizeof($pids)) {
foreach($pids as $pid) {
posix_kill($pid, SIGTERM);
}
foreach($pids as $pid) {
posix_kill($pid, SIGTERM);
}
}

clearTask($network_id, getmypid());
Expand All @@ -59,9 +59,9 @@ function sig_handler($signo) {
AND task='tmaster'", array($poller_id)), 'pid', 'pid');

if (sizeof($pids)) {
foreach($pids as $pid) {
posix_kill($pid);
}
foreach($pids as $pid) {
posix_kill($pid, SIGTERM);
}
}

clearTask($network_id, getmypid());
Expand Down Expand Up @@ -188,16 +188,16 @@ function sig_handler($signo) {
$networks = db_fetch_assoc_prepared('SELECT * FROM automation_networks WHERE poller_id = ?', array($poller_id));
$launched = 0;
if (sizeof($networks)) {
foreach($networks as $network) {
if (api_automation_is_time_to_start($network['id'])) {
automation_debug("Launching Network Master for '" . $network['name'] . "'\n");
exec_background(read_config_option('path_php_binary'), '-q ' . read_config_option('path_webroot') . "/poller_automation.php --poller=" . $poller_id . " --network=" . $network['id'] . ($force ? ' --force':'') . ($debug ? ' --debug':''));
$launched++;
}else{
automation_debug("Not time to Run Discovery for '" . $network['name'] . "'\n");
foreach($networks as $network) {
if (api_automation_is_time_to_start($network['id'])) {
automation_debug("Launching Network Master for '" . $network['name'] . "'\n");
exec_background(read_config_option('path_php_binary'), '-q ' . read_config_option('path_webroot') . "/poller_automation.php --poller=" . $poller_id . " --network=" . $network['id'] . ($force ? ' --force':'') . ($debug ? ' --debug':''));
$launched++;
}else{
automation_debug("Not time to Run Discovery for '" . $network['name'] . "'\n");
}
}
}
}

exit;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ function discoverDevices($network_id, $thread) {

$device = db_fetch_row_prepared('SELECT * FROM automation_ips WHERE pid = ? AND thread = ? AND status=0', array(getmypid(), $thread));

if (sizeof($device)) {
if (sizeof($device) && isset($device['ip_address'])) {
$count++;
if ($dns != '') {
$dnsname = automation_get_dns_from_ip($device['ip_address'], $dns, 300);
Expand Down Expand Up @@ -429,7 +429,9 @@ function discoverDevices($network_id, $thread) {
$snmp_sysName[0] = '';
}
$snmp_sysName_short = preg_split('/[\.]+/', strtolower($snmp_sysName[0]), -1, PREG_SPLIT_NO_EMPTY);

if(!isset($snmp_sysName_short[0])) {
$snmp_sysName_short[0] = '';
}
$exists = db_fetch_row_prepared('SELECT status, snmp_version FROM host WHERE hostname IN (?,?)', array($snmp_sysName_short[0], $snmp_sysName[0]));

if (sizeof($exists)) {
Expand Down Expand Up @@ -594,7 +596,7 @@ function isProcessRunning($pid) {
}

function killProcess($pid) {
return posix_kill($pid);
return posix_kill($pid, SIGINT);
}

function registerTask($network_id, $pid, $poller_id, $task = 'collector') {
Expand Down

0 comments on commit f276e3c

Please sign in to comment.