Browse code

core: added rpc command core.runinfo

- return runtime info: running version, uptime, ...

Daniel-Constantin Mierla authored on 24/01/2022 08:49:02
Showing 1 changed files
... ...
@@ -370,6 +370,45 @@ static void core_info(rpc_t* rpc, void* c)
370 370
 
371 371
 
372 372
 
373
+static const char* core_runinfo_doc[] = {
374
+	"Runtime info - binary name, version, uptime, ...", /* Documentation string */
375
+	0                             /* Method signature(s) */
376
+};
377
+
378
+static void core_runinfo(rpc_t* rpc, void* c)
379
+{
380
+	void* s;
381
+	time_t now;
382
+	char buf[MAX_CTIME_LEN];
383
+	str snow;
384
+	snow.s = buf;
385
+	int uptime;
386
+
387
+	time(&now);
388
+
389
+	if (rpc->add(c, "{", &s) < 0) {
390
+		rpc->fault(c, 500, "Server failure");
391
+		return;
392
+	}
393
+	rpc->struct_add(s, "s", "name", ver_name);
394
+	rpc->struct_add(s, "s", "version", ver_version);
395
+	rpc->struct_add(s, "s", "sourceid", ver_id);
396
+	rpc->struct_add(s, "s", "compiler", ver_compiler);
397
+	rpc->struct_add(s, "s", "compiled", ver_compiled_time);
398
+	if(ctime_r(&now, snow.s)) {
399
+		snow.len = strlen(snow.s);
400
+		if(snow.len>2 && snow.s[snow.len-1]=='\n') snow.len--;
401
+		rpc->struct_add(s, "S", "time_now", &snow);
402
+	}
403
+	rpc->struct_add(s, "s", "time_started", up_since_ctime);
404
+	uptime = (int)(now-up_since);
405
+	rpc->struct_add(s, "d", "uptime_secs", uptime);
406
+	rpc->struct_printf(s, "utime_days", "%dd %dh %dm %ds",
407
+			uptime/86400, (uptime%86400)/3600,  ((uptime%86400)%3600)/60,
408
+			((uptime%86400)%3600)%60);
409
+
410
+}
411
+
373 412
 static const char* core_uptime_doc[] = {
374 413
 	"Returns uptime of SIP server.",  /* Documentation string */
375 414
 	0                                 /* Method signature(s) */
... ...
@@ -1079,6 +1118,8 @@ static rpc_export_t core_rpc_methods[] = {
1079 1118
 		0        },
1080 1119
 	{"core.info",              core_info,              core_info_doc,
1081 1120
 		0        },
1121
+	{"core.runinfo",           core_runinfo,           core_runinfo_doc,
1122
+		0        },
1082 1123
 	{"core.uptime",            core_uptime,            core_uptime_doc,            0        },
1083 1124
 	{"core.ps",                core_ps,                core_ps_doc,                RET_ARRAY},
1084 1125
 	{"core.psx",               core_psx,               core_psx_doc,               RET_ARRAY},