Skip to content

Commit

Permalink
tools/nut-scanner/{scan_xml_http.c,scan_snmp.c,scan_nut.c,scan_ipmi.c…
Browse files Browse the repository at this point in the history
…}: report the IP address (range, single, none) in the log [networkupstools#2244]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 4, 2024
1 parent edf3c7e commit 7d8a9cb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
14 changes: 12 additions & 2 deletions tools/nut-scanner/scan_ipmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t
/* Are we scanning locally, or over the network? */
if (IPaddr == NULL)
{
upsdebugx(2, "Entering %s for local device scan", __func__);

/* FIXME: we need root right to access local IPMI!
if (!ipmi_is_root ()) {
fprintf(stderr, "IPMI scan: %s\n", ipmi_ctx_strerror (IPMI_ERR_PERMISSION));
Expand Down Expand Up @@ -433,6 +435,8 @@ nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t
}
else {

upsdebugx(2, "Entering %s for %s", __func__, IPaddr);

#if 0
if (ipmi_sec->ipmi_version == IPMI_2_0) {

Expand Down Expand Up @@ -608,14 +612,20 @@ nutscan_device_t * nutscan_scan_ipmi(const char * start_ip, const char * stop_ip
return NULL;
}


/* Are we scanning locally, or through the network? */
if (start_ip == NULL)
{
/* Local PSU scan */
upsdebugx(1, "%s: Local PSU scan", __func__);
current_nut_dev = nutscan_scan_ipmi_device(NULL, NULL);
}
else {
if (start_ip == stop_ip || !stop_ip) {
upsdebugx(1, "%s: Scanning remote PSU for single IP address: %s",
__func__, start_ip);
} else {
upsdebugx(1, "%s: Scanning remote PSU for IP address range: %s .. %s",
__func__, start_ip, stop_ip);
}
ip_str = nutscan_ip_iter_init(&ip, start_ip, stop_ip);

while (ip_str != NULL) {
Expand Down
12 changes: 12 additions & 0 deletions tools/nut-scanner/scan_nut.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ static void * list_nut_devices(void * arg)
query[0] = "UPS";
numq = 1;

upsdebugx(2, "Entering %s for %s", __func__, target_hostname);

if ((*nut_upscli_splitaddr)(target_hostname, &hostname, &port) != 0) {
free(target_hostname);
free(nut_arg);
Expand Down Expand Up @@ -301,6 +303,16 @@ nutscan_device_t * nutscan_scan_nut(const char* startIP, const char* stopIP, con
return NULL;
}

if (!startIP) {
upsdebugx(1, "%s: no starting IP address specified", __func__);
} else if (startIP == stopIP || !stopIP) {
upsdebugx(1, "%s: Scanning \"Old NUT\" bus for single IP address: %s",
__func__, startIP);
} else {
upsdebugx(1, "%s: Scanning \"Old NUT\" bus for IP address range: %s .. %s",
__func__, startIP, stopIP);
}

#ifndef WIN32
/* Ignore SIGPIPE if the caller hasn't set a handler for it yet */
if (sigaction(SIGPIPE, NULL, &oldact) == 0) {
Expand Down
10 changes: 10 additions & 0 deletions tools/nut-scanner/scan_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,16 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip
return NULL;
}

if (!start_ip) {
upsdebugx(1, "%s: no starting IP address specified", __func__);
} else if (start_ip == stop_ip || !stop_ip) {
upsdebugx(1, "%s: Scanning SNMP for single IP address: %s",
__func__, start_ip);
} else {
upsdebugx(1, "%s: Scanning SNMP for IP address range: %s .. %s",
__func__, start_ip, stop_ip);
}

g_usec_timeout = usec_timeout;

/* Force numeric OIDs resolution (ie, do not resolve to textual names)
Expand Down
10 changes: 8 additions & 2 deletions tools/nut-scanner/scan_xml_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,11 @@ nutscan_device_t * nutscan_scan_xml_http_range(const char * start_ip, const char
}

if (start_ip == NULL) {
upsdebugx(1, "Scanning XML/HTTP bus using broadcast.");
upsdebugx(1, "%s: Scanning XML/HTTP bus using broadcast.", __func__);
} else {
if ((start_ip == end_ip) || (end_ip == NULL) || (0 == strncmp(start_ip, end_ip, 128))) {
upsdebugx(1, "Scanning XML/HTTP bus for single IP (%s).", start_ip);
upsdebugx(1, "%s: Scanning XML/HTTP bus for single IP address: %s",
__func__, start_ip);
} else {
/* Iterate the range of IPs to scan */
nutscan_ip_iter_t ip;
Expand All @@ -449,7 +450,12 @@ nutscan_device_t * nutscan_scan_xml_http_range(const char * start_ip, const char
# if (defined HAVE_PTHREAD_TRYJOIN) || (defined HAVE_SEMAPHORE)
size_t max_threads_scantype = max_threads_netxml;
# endif
#endif

upsdebugx(1, "%s: Scanning XML/HTTP bus for IP address range: %s .. %s",
__func__, start_ip, end_ip);

#ifdef HAVE_PTHREAD
pthread_mutex_init(&dev_mutex, NULL);

# ifdef HAVE_SEMAPHORE
Expand Down

0 comments on commit 7d8a9cb

Please sign in to comment.