Always add timestamp to JSON output (#1436).

Move non-JSON timestamp output to common function.

git-svn-id: http://svn.code.sf.net/p/smartmontools/code/trunk@5200 4ea69e1a-61f1-4043-bf83-b5c94c648137
pull/91/head
chrfranke 2 years ago
parent 5e10e321b2
commit 5279a70c52
  1. 5
      smartmontools/ChangeLog
  2. 7
      smartmontools/ataprint.cpp
  3. 8
      smartmontools/nvmeprint.cpp
  4. 7
      smartmontools/scsiprint.cpp
  5. 16
      smartmontools/smartctl.cpp
  6. 7
      smartmontools/smartctl.h

@ -1,5 +1,10 @@
$Id$
2021-02-07 Christian Franke <franke@computer.org>
Always add timestamp to JSON output (#1436).
Move non-JSON timestamp output to common function.
2021-02-01 Christian Franke <franke@computer.org>
Silence more cppcheck 2.3 warnings.

@ -798,12 +798,7 @@ static void print_drive_info(const ata_identify_device * drive,
break;
}
// print current time and date and timezone
time_t now = time(0);
char timedatetz[DATEANDEPOCHLEN]; dateandtimezoneepoch(timedatetz, now);
jout("Local Time is: %s\n", timedatetz);
jglb["local_time"]["time_t"] = now;
jglb["local_time"]["asctime"] = timedatetz;
jout_startup_datetime("Local Time is: ");
// Print warning message, if there is one
if (dbentry && *dbentry->warningmsg)

@ -3,7 +3,7 @@
*
* Home page of code is: https://www.smartmontools.org
*
* Copyright (C) 2016-20 Christian Franke
* Copyright (C) 2016-21 Christian Franke
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
@ -201,11 +201,7 @@ static void print_drive_info(const nvme_id_ctrl & id_ctrl, const nvme_id_ns & id
}
}
time_t now = time(0);
char td[DATEANDEPOCHLEN]; dateandtimezoneepoch(td, now);
jout("Local Time is: %s\n", td);
jglb["local_time"]["time_t"] = now;
jglb["local_time"]["asctime"] = td;
jout_startup_datetime("Local Time is: ");
}
// Format scaled power value.

@ -2131,12 +2131,7 @@ scsiGetDriveInfo(scsi_device * device, uint8_t * peripheral_type, bool all)
if ((transport >= 0) && (transport <= 0xf))
pout("Transport protocol: %s\n", transport_proto_arr[transport]);
// print current time and date and timezone
time_t now = time(0);
char timedatetz[DATEANDEPOCHLEN]; dateandtimezoneepoch(timedatetz, now);
jout("Local Time is: %s\n", timedatetz);
jglb["local_time"]["time_t"] = now;
jglb["local_time"]["asctime"] = timedatetz;
jout_startup_datetime("Local Time is: ");
// See if unit accepts SCSI commands from us
if ((err = scsiTestUnitReady(device))) {

@ -1412,6 +1412,14 @@ void jerr(const char *fmt, ...)
va_end(ap);
}
static char startup_datetime_buf[DATEANDEPOCHLEN];
// Print smartctl start-up date and time and timezone
void jout_startup_datetime(const char *prefix)
{
jout("%s%s\n", prefix, startup_datetime_buf);
}
// Globals to set failuretest() policy
bool failuretest_conservative = false;
unsigned char failuretest_permissive = 0;
@ -1556,6 +1564,14 @@ static int main_worker(int argc, char **argv)
return status;
}
// Store formatted current time for jout_startup_datetime()
// Output as JSON regardless of '-i' option
{
time_t now = time(nullptr);
dateandtimezoneepoch(startup_datetime_buf, now);
jglb["local_time"] += { {"time_t", now}, {"asctime", startup_datetime_buf} };
}
const char * name = argv[argc-1];
smart_device_auto_ptr dev;

@ -1,10 +1,10 @@
/*
* smartctl.h
*
* Home page of code is: http://www.smartmontools.org
* Home page of code is: https://www.smartmontools.org
*
* Copyright (C) 2002-10 Bruce Allen
* Copyright (C) 2008-17 Christian Franke
* Copyright (C) 2008-21 Christian Franke
* Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
@ -100,4 +100,7 @@ __attribute_format_printf(1, 2);
void jerr(const char *fmt, ...)
__attribute_format_printf(1, 2);
// Print smartctl start-up date and time and timezone
void jout_startup_datetime(const char *prefix);
#endif

Loading…
Cancel
Save