aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2019-11-07 16:59:15 +0100
committerDaniel Willmann <dwillmann@sysmocom.de>2019-11-11 14:55:46 +0100
commit85d0fb2b38c87bf0dd06e445f5603412a2f9b8ad (patch)
treeda1db85ad38cb5505b88c54f0cb9532761091e56
parent66a83f495f997143ead409d581bd2cd910dad46f (diff)
Cleaner output if sections are empty
Even with a completely empty config we still get the following output: root sysinfo load: 0.87/0.92/0.98 ram: 243/168/0 uptime: 1d 22:18:19 netdev ping file shellcmd With this patch the sections are skipped if there are no entries and the command no sysinfo can be used to skip displaying the system information. Change-Id: I429fe7626b43aef74ff7458f5c2864888fa9a562
-rw-r--r--src/osysmon_file.c3
-rw-r--r--src/osysmon_ping.c9
-rw-r--r--src/osysmon_rtnl.c3
-rw-r--r--src/osysmon_shellcmd.c3
-rw-r--r--src/osysmon_sysinfo.c55
5 files changed, 59 insertions, 14 deletions
diff --git a/src/osysmon_file.c b/src/osysmon_file.c
index 1dec3db..8e52497 100644
--- a/src/osysmon_file.c
+++ b/src/osysmon_file.c
@@ -153,6 +153,9 @@ int osysmon_file_poll(struct value_node *parent)
struct value_node *vn_file;
struct osysmon_file *of;
+ if (llist_empty(&g_oss->files))
+ return 0;
+
vn_file = value_node_add(parent, "file", NULL);
llist_for_each_entry(of, &g_oss->files, list)
diff --git a/src/osysmon_ping.c b/src/osysmon_ping.c
index f736798..3484374 100644
--- a/src/osysmon_ping.c
+++ b/src/osysmon_ping.c
@@ -229,6 +229,10 @@ int osysmon_ping_poll(struct value_node *parent)
struct value_node *vn_host;
int num_host = iterator_count(g_oss->pings->ping_handle);
pingobj_iter_t *iter;
+
+ if (!num_host)
+ return 0;
+
struct value_node *vn_ping = value_node_add(parent, "ping", NULL);
if (!vn_ping)
return -ENOMEM;
@@ -257,8 +261,5 @@ int osysmon_ping_poll(struct value_node *parent)
add_ttl(iter, vn_host);
}
- if (num_host)
- return ping_send(g_oss->pings->ping_handle);
-
- return 0;
+ return ping_send(g_oss->pings->ping_handle);
}
diff --git a/src/osysmon_rtnl.c b/src/osysmon_rtnl.c
index 9fd4251..f1e5a0e 100644
--- a/src/osysmon_rtnl.c
+++ b/src/osysmon_rtnl.c
@@ -401,6 +401,9 @@ int osysmon_rtnl_poll(struct value_node *parent)
{
struct value_node *vn_net;
+ if (llist_empty(&g_oss->netdevs))
+ return 0;
+
if (!g_oss->rcs)
g_oss->rcs = rtnl_init(NULL);
diff --git a/src/osysmon_shellcmd.c b/src/osysmon_shellcmd.c
index 347b982..83dc0c9 100644
--- a/src/osysmon_shellcmd.c
+++ b/src/osysmon_shellcmd.c
@@ -165,6 +165,9 @@ int osysmon_shellcmd_poll(struct value_node *parent)
struct value_node *vn_file;
struct osysmon_shellcmd *oc;
+ if (llist_empty(&g_oss->shellcmds))
+ return 0;
+
vn_file = value_node_add(parent, "shellcmd", NULL);
llist_for_each_entry(oc, &g_oss->shellcmds, list)
diff --git a/src/osysmon_sysinfo.c b/src/osysmon_sysinfo.c
index 85d9ee9..9cb434c 100644
--- a/src/osysmon_sysinfo.c
+++ b/src/osysmon_sysinfo.c
@@ -30,16 +30,6 @@
#include "osysmon.h"
#include "value_node.h"
-/***********************************************************************
- * Runtime Code
- ***********************************************************************/
-
-/* called once on startup before config file parsing */
-int osysmon_sysinfo_init()
-{
- return 0;
-}
-
static float loadfac(unsigned long in) {
return in/65536.0;
}
@@ -55,6 +45,48 @@ static float loadfac(unsigned long in) {
#define to_minutes(in) (((in)/(SECS_PER_MIN))%MINS_PER_HOUR)
#define to_seconds(in) ((in)%SECS_PER_MIN)
+static bool sysinfo_enabled = true;
+
+/***********************************************************************
+ * VTY
+ ***********************************************************************/
+
+#define CMD_STR "Display sysinfo\n"
+DEFUN(cfg_sysinfo, cfg_sysinfo_cmd,
+ "sysinfo",
+ CMD_STR)
+{
+ sysinfo_enabled = true;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_no_sysinfo, cfg_no_sysinfo_cmd,
+ "no sysinfo",
+ NO_STR CMD_STR)
+{
+ sysinfo_enabled = false;
+
+ return CMD_SUCCESS;
+}
+
+static void osysmon_sysinfo_vty_init(void)
+{
+ install_element(CONFIG_NODE, &cfg_sysinfo_cmd);
+ install_element(CONFIG_NODE, &cfg_no_sysinfo_cmd);
+}
+
+/***********************************************************************
+ * Runtime Code
+ ***********************************************************************/
+
+/* called once on startup before config file parsing */
+int osysmon_sysinfo_init()
+{
+ osysmon_sysinfo_vty_init();
+ return 0;
+}
+
/* called periodically */
int osysmon_sysinfo_poll(struct value_node *parent)
{
@@ -63,6 +95,9 @@ int osysmon_sysinfo_poll(struct value_node *parent)
char buf[32];
int rc;
+ if (!sysinfo_enabled)
+ return 0;
+
vn_sysinfo = value_node_add(parent, "sysinfo", NULL);
rc = sysinfo(&si);