Let Probe compile again

This commit is contained in:
Pierre Pronchery 2014-05-08 01:15:36 +02:00
parent 0b3d50f699
commit 37b47bd343
3 changed files with 114 additions and 104 deletions

View File

@ -1,6 +1,5 @@
#$Id$ #$Id$
service=Probe service=Probe
port=4243
[call::uptime] [call::uptime]
ret=UINT32 ret=UINT32

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2005-2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Network Probe */ /* This file is part of DeforaOS Network Probe */
/* This program is free software: you can redistribute it and/or modify /* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -32,8 +32,14 @@
#ifndef PREFIX #ifndef PREFIX
# define PREFIX "/usr/local" # define PREFIX "/usr/local"
#endif #endif
#ifndef ETCDIR #ifndef SYSCONFDIR
# define ETCDIR PREFIX "/etc" # define SYSCONFDIR PREFIX "/etc"
#endif
#ifndef PROGNAME
# define PROGNAME "DaMon"
#endif
#ifndef RRDTOOL
# define RRDTOOL "rrdtool"
#endif #endif
@ -63,7 +69,6 @@ struct _DaMon
/* constants */ /* constants */
#define DAMON_DEFAULT_REFRESH 10 #define DAMON_DEFAULT_REFRESH 10
#define DAMON_PROGNAME "DaMon"
#define DAMON_SEP '/' #define DAMON_SEP '/'
@ -84,7 +89,7 @@ static int _damon(char const * config)
if(_damon_init(&damon, config) != 0) if(_damon_init(&damon, config) != 0)
return 1; return 1;
if(event_loop(damon.event) != 0) if(event_loop(damon.event) != 0)
error_print(DAMON_PROGNAME); error_print(PROGNAME);
_damon_destroy(&damon); _damon_destroy(&damon);
return 1; return 1;
} }
@ -101,7 +106,7 @@ static int _damon_init(DaMon * damon, char const * filename)
if(_init_config(damon, filename) != 0) if(_init_config(damon, filename) != 0)
return 1; return 1;
if((damon->event = event_new()) == NULL) if((damon->event = event_new()) == NULL)
return error_print(DAMON_PROGNAME); return error_print(PROGNAME);
_damon_refresh(damon); _damon_refresh(damon);
tv.tv_sec = damon->refresh; tv.tv_sec = damon->refresh;
tv.tv_usec = 0; tv.tv_usec = 0;
@ -127,10 +132,10 @@ static int _init_config(DaMon * damon, char const * filename)
damon->hosts = NULL; damon->hosts = NULL;
damon->hosts_cnt = 0; damon->hosts_cnt = 0;
if(filename == NULL) if(filename == NULL)
filename = ETCDIR "/" DAMON_PROGNAME ".conf"; filename = SYSCONFDIR "/" PROGNAME ".conf";
if(config_load(config, filename) != 0) if(config_load(config, filename) != 0)
{ {
error_print(DAMON_PROGNAME); error_print(PROGNAME);
config_delete(config); config_delete(config);
return 1; return 1;
} }
@ -324,9 +329,9 @@ static AppClient * _refresh_connect(Host * host, Event * event)
{ {
if(setenv("APPSERVER_Probe", host->hostname, 1) != 0) if(setenv("APPSERVER_Probe", host->hostname, 1) != 0)
return NULL; return NULL;
if((host->appclient = appclient_new_event("Probe", event)) if((host->appclient = appclient_new_event(NULL, "Probe", NULL, event))
== NULL) == NULL)
error_print(DAMON_PROGNAME); error_print(PROGNAME);
return host->appclient; return host->appclient;
} }
@ -335,8 +340,8 @@ static int _refresh_uptime(AppClient * ac, Host * host, char * rrd)
{ {
int32_t ret; int32_t ret;
if(appclient_call(ac, &ret, "uptime") != 0) if(appclient_call(ac, (void **)&ret, "uptime") != 0)
return error_print(DAMON_PROGNAME); return error_print(PROGNAME);
sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "uptime.rrd"); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "uptime.rrd");
_rrd_update(host->damon, rrd, 1, ret); _rrd_update(host->damon, rrd, 1, ret);
return 0; return 0;
@ -347,8 +352,9 @@ static int _refresh_load(AppClient * ac, Host * host, char * rrd)
int32_t res; int32_t res;
uint32_t load[3]; uint32_t load[3];
if(appclient_call(ac, &res, "load", &load[0], &load[1], &load[2]) != 0) if(appclient_call(ac, (void **)&res, "load", &load[0], &load[1],
return error_print(DAMON_PROGNAME); &load[2]) != 0)
return error_print(PROGNAME);
if(res != 0) if(res != 0)
return 0; return 0;
sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "load.rrd"); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "load.rrd");
@ -360,7 +366,7 @@ static int _refresh_procs(AppClient * ac, Host * host, char * rrd)
{ {
int32_t res; int32_t res;
if(appclient_call(ac, &res, "procs") != 0) if(appclient_call(ac, (void **)&res, "procs") != 0)
return 1; return 1;
sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "procs.rrd"); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "procs.rrd");
_rrd_update(host->damon, rrd, 1, res); _rrd_update(host->damon, rrd, 1, res);
@ -372,8 +378,8 @@ static int _refresh_ram(AppClient * ac, Host * host, char * rrd)
int32_t res; int32_t res;
uint32_t ram[4]; uint32_t ram[4];
if(appclient_call(ac, &res, "ram", &ram[0], &ram[1], &ram[2], &ram[3]) if(appclient_call(ac, (void **)&res, "ram", &ram[0], &ram[1], &ram[2],
!= 0) &ram[3]) != 0)
return 1; return 1;
sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "ram.rrd"); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "ram.rrd");
_rrd_update(host->damon, rrd, 4, ram[0], ram[1], ram[2], ram[3]); _rrd_update(host->damon, rrd, 4, ram[0], ram[1], ram[2], ram[3]);
@ -385,7 +391,7 @@ static int _refresh_swap(AppClient * ac, Host * host, char * rrd)
int32_t res; int32_t res;
uint32_t swap[2]; uint32_t swap[2];
if(appclient_call(ac, &res, "swap", &swap[0], &swap[1]) != 0) if(appclient_call(ac, (void **)&res, "swap", &swap[0], &swap[1]) != 0)
return 1; return 1;
sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "swap.rrd"); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "swap.rrd");
_rrd_update(host->damon, rrd, 2, swap[0], swap[1]); _rrd_update(host->damon, rrd, 2, swap[0], swap[1]);
@ -396,7 +402,7 @@ static int _refresh_users(AppClient * ac, Host * host, char * rrd)
{ {
int32_t res; int32_t res;
if(appclient_call(ac, &res, "users") != 0) if(appclient_call(ac, (void **)&res, "users") != 0)
return 1; return 1;
sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "users.rrd"); sprintf(rrd, "%s%c%s", host->hostname, DAMON_SEP, "users.rrd");
_rrd_update(host->damon, rrd, 1, res); _rrd_update(host->damon, rrd, 1, res);
@ -422,8 +428,9 @@ static int _ifaces_if(AppClient * ac, Host * host, char * rrd,
{ {
int32_t res[2]; int32_t res[2];
if(appclient_call(ac, &res[0], "ifrxbytes", iface) != 0 if(appclient_call(ac, (void **)&res[0], "ifrxbytes", iface) != 0
|| appclient_call(ac, &res[1], "iftxbytes", iface) != 0) || appclient_call(ac, (void **)&res[1], "iftxbytes",
iface) != 0)
return 1; return 1;
sprintf(rrd, "%s%c%s%s", host->hostname, DAMON_SEP, iface, ".rrd"); sprintf(rrd, "%s%c%s%s", host->hostname, DAMON_SEP, iface, ".rrd");
_rrd_update(host->damon, rrd, 2, res[0], res[1]); _rrd_update(host->damon, rrd, 2, res[0], res[1]);
@ -447,8 +454,8 @@ static int _vols_vol(AppClient * ac, Host * host, char * rrd, char * vol)
{ {
int32_t res[2]; int32_t res[2];
if(appclient_call(ac, &res[0], "voltotal", vol) != 0 if(appclient_call(ac, (void **)&res[0], "voltotal", vol) != 0
|| appclient_call(ac, &res[1], "volfree", vol) || appclient_call(ac, (void **)&res[1], "volfree", vol)
!= 0) != 0)
return 1; return 1;
sprintf(rrd, "%s%s%s", host->hostname, vol, ".rrd"); /* FIXME */ sprintf(rrd, "%s%s%s", host->hostname, vol, ".rrd"); /* FIXME */
@ -459,7 +466,7 @@ static int _vols_vol(AppClient * ac, Host * host, char * rrd, char * vol)
static int _exec(char * argv[]); static int _exec(char * argv[]);
static int _rrd_update(DaMon * damon, char const * filename, int args_cnt, ...) static int _rrd_update(DaMon * damon, char const * filename, int args_cnt, ...)
{ {
char * argv[] = { "rrdtool", "update", NULL, NULL, NULL }; char * argv[] = { RRDTOOL, "update", NULL, NULL, NULL };
struct timeval tv; struct timeval tv;
int pos; int pos;
int i; int i;
@ -514,7 +521,7 @@ static int _exec(char * argv[])
/* private */ /* private */
static int _damon_perror(char const * message, int ret) static int _damon_perror(char const * message, int ret)
{ {
return error_set_print(DAMON_PROGNAME, ret, "%s%s%s\n", return error_set_print(PROGNAME, ret, "%s%s%s\n",
message ? message : "", message ? message : "",
message ? ": " : "", strerror(errno)); message ? ": " : "", strerror(errno));
} }
@ -523,7 +530,7 @@ static int _damon_perror(char const * message, int ret)
/* usage */ /* usage */
static int _usage(void) static int _usage(void)
{ {
fputs("Usage: " DAMON_PROGNAME " [-f filename]\n" fputs("Usage: " PROGNAME " [-f filename]\n"
" -f\tConfiguration file to load\n", stderr); " -f\tConfiguration file to load\n", stderr);
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2005-2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Network Probe */ /* This file is part of DeforaOS Network Probe */
/* This program is free software: you can redistribute it and/or modify /* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -29,6 +29,10 @@
#include "../data/Probe.h" #include "../data/Probe.h"
#include "../config.h" #include "../config.h"
#ifndef PROGNAME
# define PROGNAME PACKAGE
#endif
#if defined(__linux__) #if defined(__linux__)
# define _sysinfo_linux _sysinfo # define _sysinfo_linux _sysinfo
@ -580,7 +584,7 @@ static int _volinfo_generic(struct volinfo ** dev)
/* Probe */ /* Probe */
/* private */ /* private */
/* types */ /* types */
typedef struct _Probe typedef struct _App
{ {
struct sysinfo sysinfo; struct sysinfo sysinfo;
unsigned int users; unsigned int users;
@ -591,10 +595,6 @@ typedef struct _Probe
} Probe; } Probe;
/* variables */
Probe probe;
/* prototypes */ /* prototypes */
static int _probe_error(int ret); static int _probe_error(int ret);
static int _probe_perror(char const * message, int ret); static int _probe_perror(char const * message, int ret);
@ -605,6 +605,7 @@ static int _probe_timeout(Probe * probe);
/* probe */ /* probe */
static int _probe(AppServerOptions options) static int _probe(AppServerOptions options)
{ {
Probe probe;
AppServer * appserver; AppServer * appserver;
Event * event; Event * event;
struct timeval tv; struct timeval tv;
@ -622,8 +623,8 @@ static int _probe(AppServerOptions options)
free(probe.volinfo); free(probe.volinfo);
return _probe_error(1); return _probe_error(1);
} }
if((appserver = appserver_new_event("Probe", options, event)) if((appserver = appserver_new_event(&probe, options, "Probe", NULL,
== NULL) event)) == NULL)
{ {
free(probe.ifinfo); free(probe.ifinfo);
free(probe.volinfo); free(probe.volinfo);
@ -648,7 +649,7 @@ static int _probe(AppServerOptions options)
/* probe_error */ /* probe_error */
static int _probe_error(int ret) static int _probe_error(int ret)
{ {
error_print(PACKAGE); error_print(PROGNAME);
return ret; return ret;
} }
@ -656,7 +657,7 @@ static int _probe_error(int ret)
/* probe_perror */ /* probe_perror */
static int _probe_perror(char const * message, int ret) static int _probe_perror(char const * message, int ret)
{ {
error_set_print(PACKAGE, ret, "%s%s%s", message ? message : "", error_set_print(PROGNAME, ret, "%s%s%s", message ? message : "",
message ? ": " : "", strerror(errno)); message ? ": " : "", strerror(errno));
return ret; return ret;
} }
@ -689,156 +690,162 @@ static int _probe_timeout(Probe * probe)
/* functions */ /* functions */
/* AppInterface */ /* AppInterface */
/* Probe_uptime */ /* Probe_uptime */
uint32_t Probe_uptime(void) uint32_t Probe_uptime(Probe * probe, AppServerClient * asc)
{ {
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%ld%s", "Uptime: ", probe.sysinfo.uptime, "\n"); printf("%s%ld%s", "Uptime: ", probe->sysinfo.uptime, "\n");
#endif #endif
return probe.sysinfo.uptime; return probe->sysinfo.uptime;
} }
/* Probe_load */ /* Probe_load */
int32_t Probe_load(uint32_t * load1, uint32_t * load5, uint32_t * load15) int32_t Probe_load(Probe * probe, AppServerClient * asc, uint32_t * load1,
uint32_t * load5, uint32_t * load15)
{ {
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%lu%s%lu%s%lu%s", "Load 1: ", probe.sysinfo.loads[0], printf("%s%lu%s%lu%s%lu%s", "Load 1: ", probe->sysinfo.loads[0],
", Load 5: ", probe.sysinfo.loads[1], ", Load 5: ", probe->sysinfo.loads[1],
", Load 15: ", probe.sysinfo.loads[2], "\n"); ", Load 15: ", probe->sysinfo.loads[2], "\n");
#endif #endif
*load1 = probe.sysinfo.loads[0]; *load1 = probe->sysinfo.loads[0];
*load5 = probe.sysinfo.loads[1]; *load5 = probe->sysinfo.loads[1];
*load15 = probe.sysinfo.loads[2]; *load15 = probe->sysinfo.loads[2];
return 0; return 0;
} }
/* Probe_ram */ /* Probe_ram */
int32_t Probe_ram(uint32_t * total, uint32_t * free, uint32_t * shared, int32_t Probe_ram(Probe * probe, AppServerClient * asc, uint32_t * total,
uint32_t * buffer) uint32_t * free, uint32_t * shared, uint32_t * buffer)
{ {
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%lu%s%lu%s%lu%s%lu%s", printf("%s%lu%s%lu%s%lu%s%lu%s",
"Total RAM: ", probe.sysinfo.totalram, "Total RAM: ", probe->sysinfo.totalram,
", Free RAM: ", probe.sysinfo.freeram, ", Free RAM: ", probe->sysinfo.freeram,
", Shared RAM: ", probe.sysinfo.sharedram, ", Shared RAM: ", probe->sysinfo.sharedram,
", Buffered RAM: ", probe.sysinfo.bufferram, "\n"); ", Buffered RAM: ", probe->sysinfo.bufferram, "\n");
#endif #endif
*total = probe.sysinfo.totalram; *total = probe->sysinfo.totalram;
*free = probe.sysinfo.freeram; *free = probe->sysinfo.freeram;
*shared = probe.sysinfo.sharedram; *shared = probe->sysinfo.sharedram;
*buffer = probe.sysinfo.bufferram; *buffer = probe->sysinfo.bufferram;
return 0; return 0;
} }
/* Probe_swap */ /* Probe_swap */
int32_t Probe_swap(uint32_t * total, uint32_t * free) int32_t Probe_swap(Probe * probe, AppServerClient * asc, uint32_t * total,
uint32_t * free)
{ {
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%lu%s", "Total swap: ", probe.sysinfo.totalswap, "\n"); printf("%s%lu%s", "Total swap: ", probe->sysinfo.totalswap, "\n");
printf("%s%lu%s", "Free swap: ", probe.sysinfo.freeswap, "\n"); printf("%s%lu%s", "Free swap: ", probe->sysinfo.freeswap, "\n");
#endif #endif
*total = probe.sysinfo.totalswap; *total = probe->sysinfo.totalswap;
*free = probe.sysinfo.freeswap; *free = probe->sysinfo.freeswap;
return 0; return 0;
} }
/* Probe_procs */ /* Probe_procs */
uint32_t Probe_procs(void) uint32_t Probe_procs(Probe * probe, AppServerClient * asc)
{ {
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%u%s", "Procs: ", probe.sysinfo.procs, "\n"); printf("%s%u%s", "Procs: ", probe->sysinfo.procs, "\n");
#endif #endif
return probe.sysinfo.procs; return probe->sysinfo.procs;
} }
/* Probe_users */ /* Probe_users */
uint32_t Probe_users(void) uint32_t Probe_users(Probe * probe, AppServerClient * asc)
{ {
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%u%s", "Users: ", probe.users, "\n"); printf("%s%u%s", "Users: ", probe->users, "\n");
#endif #endif
return probe.users; return probe->users;
} }
/* Probe_ifrxbytes */ /* Probe_ifrxbytes */
uint32_t Probe_ifrxbytes(String const * dev) uint32_t Probe_ifrxbytes(Probe * probe, AppServerClient * asc,
String const * dev)
{ {
unsigned int i; unsigned int i;
for(i = 0; i < probe.ifinfo_cnt for(i = 0; i < probe->ifinfo_cnt
&& string_compare(probe.ifinfo[i].name, dev) != 0; i++); && string_compare(probe->ifinfo[i].name, dev) != 0; i++);
if(i == probe.ifinfo_cnt) if(i == probe->ifinfo_cnt)
return -1; return -1;
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%s%s%u%s", "Interface ", probe.ifinfo[i].name, " RX: ", printf("%s%s%s%u%s", "Interface ", probe->ifinfo[i].name, " RX: ",
probe.ifinfo[i].ibytes, "\n"); probe->ifinfo[i].ibytes, "\n");
#endif #endif
return probe.ifinfo[i].ibytes; return probe->ifinfo[i].ibytes;
} }
/* Probe_iftxbytes */ /* Probe_iftxbytes */
uint32_t Probe_iftxbytes(String const * dev) uint32_t Probe_iftxbytes(Probe * probe, AppServerClient * asc,
String const * dev)
{ {
unsigned int i; unsigned int i;
for(i = 0; i < probe.ifinfo_cnt for(i = 0; i < probe->ifinfo_cnt
&& string_compare(probe.ifinfo[i].name, dev) != 0; i++); && string_compare(probe->ifinfo[i].name, dev) != 0; i++);
if(i == probe.ifinfo_cnt) if(i == probe->ifinfo_cnt)
return -1; return -1;
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%s%s%u%s", "Interface ", probe.ifinfo[i].name, " TX: ", printf("%s%s%s%u%s", "Interface ", probe->ifinfo[i].name, " TX: ",
probe.ifinfo[i].obytes, "\n"); probe->ifinfo[i].obytes, "\n");
#endif #endif
return probe.ifinfo[i].obytes; return probe->ifinfo[i].obytes;
} }
/* Probe_voltotal */ /* Probe_voltotal */
uint32_t Probe_voltotal(String const * volume) uint32_t Probe_voltotal(Probe * probe, AppServerClient * asc,
String const * volume)
{ {
unsigned int i; unsigned int i;
for(i = 0; i < probe.volinfo_cnt for(i = 0; i < probe->volinfo_cnt
&& string_compare(probe.volinfo[i].name, volume) != 0; && string_compare(probe->volinfo[i].name, volume) != 0;
i++); i++);
if(i == probe.volinfo_cnt) if(i == probe->volinfo_cnt)
return -1; return -1;
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%s%s%lu%s", "Volume ", probe.volinfo[i].name, " total: ", printf("%s%s%s%lu%s", "Volume ", probe->volinfo[i].name, " total: ",
probe.volinfo[i].total, "\n"); probe->volinfo[i].total, "\n");
#endif #endif
return probe.volinfo[i].total * (probe.volinfo[i].block_size / 1024); return probe->volinfo[i].total * (probe->volinfo[i].block_size / 1024);
} }
/* Probe_volfree */ /* Probe_volfree */
uint32_t Probe_volfree(String const * volume) uint32_t Probe_volfree(Probe * probe, AppServerClient * asc,
String const * volume)
{ {
unsigned int i; unsigned int i;
for(i = 0; i < probe.volinfo_cnt for(i = 0; i < probe->volinfo_cnt
&& string_compare(probe.volinfo[i].name, volume) != 0; && string_compare(probe->volinfo[i].name, volume) != 0;
i++); i++);
if(i == probe.volinfo_cnt) if(i == probe->volinfo_cnt)
return -1; return -1;
#if defined(DEBUG) #if defined(DEBUG)
printf("%s%s%s%lu%s", "Volume ", probe.volinfo[i].name, " free: ", printf("%s%s%s%lu%s", "Volume ", probe->volinfo[i].name, " free: ",
probe.volinfo[i].free, "\n"); probe->volinfo[i].free, "\n");
#endif #endif
return probe.volinfo[i].free * (probe.volinfo[i].block_size / 1024); return probe->volinfo[i].free * (probe->volinfo[i].block_size / 1024);
} }
/* usage */ /* usage */
static int _usage(void) static int _usage(void)
{ {
fputs("Usage: " PACKAGE " [-L|-R]\n", stderr); fputs("Usage: " PROGNAME " [-R]\n", stderr);
return 1; return 1;
} }
@ -847,16 +854,13 @@ static int _usage(void)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int o; int o;
AppServerOptions options = ASO_LOCAL; AppServerOptions options = 0;
while((o = getopt(argc, argv, "LR")) != -1) while((o = getopt(argc, argv, "R")) != -1)
switch(o) switch(o)
{ {
case 'L':
options = ASO_LOCAL;
break;
case 'R': case 'R':
options = ASO_REMOTE; options = ASO_REGISTER;
break; break;
default: default:
return _usage(); return _usage();