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
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 @@
 	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 @@
 	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 @@
 		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 @@
 {
 	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 @@
 	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 @@
 #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 @@
 	char buf[32];
 	int rc;
 
+	if (!sysinfo_enabled)
+		return 0;
+
 	vn_sysinfo = value_node_add(parent, "sysinfo", NULL);
 
 	rc = sysinfo(&si);