Skip to content

Commit

Permalink
Correct segfault and other cleanup
Browse files Browse the repository at this point in the history
* Correct segfault due to use of wrong variable
* Remove some whitespace
* More declarations to headers
* Add 'Device[]' to some log messages
* PID[] instead of Process[]
* Some block formatting
* Remove an automake warning
* Use stdbool.h
  • Loading branch information
cigamit committed Aug 25, 2019
1 parent 07b4e65 commit 4a2d1ae
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 89 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Makefile.am -- Process this file with automake to produce Makefile.in

AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4

spine_SOURCES = sql.c spine.c util.c snmp.c locks.c poller.c nft_popen.c php.c ping.c keywords.c error.c

Expand Down
2 changes: 1 addition & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>

#include <stdbool.h>

#if HAVE_STDINT_H
# include <stdint.h>
Expand Down
51 changes: 30 additions & 21 deletions poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -1685,9 +1685,9 @@ void poll_host(int host_id, int host_thread, int last_host_thread, int host_data
/* record the polling time for the device */
poll_time = get_time_as_double() - poll_time;
if (is_debug_device(host_id)) {
SPINE_LOG(("Device[%i] HT[%i] Total Time: %5.2g Seconds", host_id, host_thread, poll_time));
SPINE_LOG(("Device[%i] HT[%i] Total Time: %0.2g Seconds", host_id, host_thread, poll_time));
} else {
SPINE_LOG_MEDIUM(("Device[%i] HT[%i] Total Time: %5.2g Seconds", host_id, host_thread, poll_time));
SPINE_LOG_MEDIUM(("Device[%i] HT[%i] Total Time: %0.2g Seconds", host_id, host_thread, poll_time));
}

/* record the total time for the host */
Expand Down Expand Up @@ -1768,70 +1768,79 @@ int is_multipart_output(char *result) {
void get_system_information(host_t *host, MYSQL *mysql, int system) {
char *poll_result;

SPINE_LOG_MEDIUM(("NOTE: Device[%d] Checking for System Information Update", host->id));

if (set.mibs || system) {
if (is_debug_device(host->id)) {
SPINE_LOG(("Updating Full System Information Table"));
SPINE_LOG(("NOTE: Device[%d] Updating Full System Information Table", host->id));
} else {
SPINE_LOG_MEDIUM(("Updating Full System Information Table"));
SPINE_LOG_MEDIUM(("NOTE: Device[%d] Updating Full System Information Table", host->id));
}

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.1.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.1.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.1.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.1.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.1.0'); [complete]", host->id));

if (poll_result) {
db_escape(mysql, host->snmp_sysDescr, sizeof(host->snmp_sysDescr), poll_result);
free(poll_result);
}
free(poll_result);

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.2.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.2.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.2.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.2.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.2.0'); [complete]", host->id));

if (poll_result) {
db_escape(mysql, host->snmp_sysObjectID, sizeof(host->snmp_sysObjectID), poll_result);
free(poll_result);
}

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.3.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDGB: Device[%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]", host->id));

if (poll_result) {
host->snmp_sysUpTimeInstance = atoi(poll_result);
free(poll_result);
}

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.4.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.4.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.4.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.4.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.4.0'); [complete]", host->id));

if (poll_result) {
db_escape(mysql, host->snmp_sysContact, sizeof(host->snmp_sysContact), poll_result);
free(poll_result);
}

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.5.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.5.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.5.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.5.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.5.0'); [complete]", host->id));

if (poll_result) {
db_escape(mysql, host->snmp_sysName, sizeof(host->snmp_sysName), poll_result);
free(poll_result);
}

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.6.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.6.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.6.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.6.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.6.0'); [complete]", host->id));

if (poll_result) {
db_escape(mysql, host->snmp_sysLocation, sizeof(host->snmp_sysLocation), poll_result);
free(poll_result);
}
} else {
if (is_debug_device(host->id)) {
SPINE_LOG(("Updating Short System Information Table"));
SPINE_LOG(("NOTE: Device[%d] Updating Short System Information Table", host->id));
} else {
SPINE_LOG_MEDIUM(("Updating Short System Information Table"));
SPINE_LOG_MEDIUM(("NOTE: Device[%d] Updating Short System Information Table", host->id));
}

SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0');", host->id));
poll_result = snmp_get(host, ".1.3.6.1.2.1.1.3.0");
SPINE_LOG_DEVDBG(("poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]"));
SPINE_LOG_DEVDBG(("DEVDBG: Device [%d] poll_result = snmp_get(host, '.1.3.6.1.2.1.1.3.0'); [complete]", host->id));

if (poll_result) {
host->snmp_sysUpTimeInstance = atoi(poll_result);
free(poll_result);
Expand Down
10 changes: 5 additions & 5 deletions snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ void snmp_spine_close(void) {
*
*/
void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_community,
char *snmp_username, char *snmp_password, char *snmp_auth_protocol,
char *snmp_priv_passphrase, char *snmp_priv_protocol,
char *snmp_context, char *snmp_engine_id, int snmp_port, int snmp_timeout) {
char *snmp_username, char *snmp_password, char *snmp_auth_protocol,
char *snmp_priv_passphrase, char *snmp_priv_protocol,
char *snmp_context, char *snmp_engine_id, int snmp_port, int snmp_timeout) {

void *sessp = NULL;
struct snmp_session session;
Expand Down Expand Up @@ -187,8 +187,8 @@ void *snmp_host_init(int host_id, char *hostname, int snmp_version, char *snmp_c
session.peername = hostnameport;
session.retries = set.snmp_retries;
session.remote_port = snmp_port;
//session.timeout = (snmp_timeout * 1000); /* net-snmp likes microseconds */
session.timeout = (snmp_timeout * 1000); /* net-snmp likes microseconds */

SPINE_LOG_MEDIUM(("Device[%i] INFO: SNMP Device '%s' has timeout %ld (%d), retries %d", host_id, hostname, session.timeout, snmp_timeout, session.retries));

if ((snmp_version == 2) || (snmp_version == 1)) {
Expand Down Expand Up @@ -346,7 +346,7 @@ char *snmp_get(host_t *current_host, char *snmp_oid) {
anOID_len = MAX_OID_LEN;

SPINE_LOG_DEVDBG(("Device[%i] WARNING: snmp_pdu_create(%s)", current_host->id, snmp_oid));
pdu = snmp_pdu_create(SNMP_MSG_GET);
pdu = snmp_pdu_create(SNMP_MSG_GET);
SPINE_LOG_DEVDBG(("Device[%i] WARNING: snmp_pdu_create(%s) [complete]", current_host->id, snmp_oid));

SPINE_LOG_DEVDBG(("Device[%i] WARNING: snmp_parse_oid(%s)", current_host->id, snmp_oid));
Expand Down
Loading

0 comments on commit 4a2d1ae

Please sign in to comment.