Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add journalctl action to sansshell with os/exec #293

Merged
merged 4 commits into from
Aug 10, 2023

Conversation

sfc-gh-pchu
Copy link
Collaborator

Description

Introducing cgo dependency will bring compiling concern for the whole project: #279. This is another way to implement journalctl action through native go package os/exec as a workaround.

  • Most of the features implemented in PR 279 will remain except the -x (add explanatory text)
  • Disable the ability to fetch whole journal entries since the buffer limit
  • by default tail will be set to 100

Test result

  • Unit test has been done in test file
  • Manual tests are also performed
    Case 1: set unit, tail, since an until
// sanssh
# ./sanssh --targets=localhost sysinfo  journalctl  -unit foundationdb -tail 10 --since "2023-06-23 18:15:58" --until "2023-06-23 18:15:59"
[2023-06-23 18:15:58.387879 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Watching conf file /etc/foundationdb/foundationdb.conf
[2023-06-23 18:15:58.388002 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Watching conf dir /etc/foundationdb/ (6)
[2023-06-23 18:15:58.388071 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Loading configuration /etc/foundationdb/foundationdb.conf
[2023-06-23 18:15:58.388144 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Found new configuration for fdbserver.4500
[2023-06-23 18:15:58.388229 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Found new configuration for fdbserver.4503
[2023-06-23 18:15:58.388302 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Updated configuration for backup_agent.1
[2023-06-23 18:15:58.388373 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Killing process 29265
[2023-06-23 18:15:58.488919 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Killing process 29264
[2023-06-23 18:15:58.587851 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbserver.4500": Launching /usr/sbin/fdbserver (29360) for fdbserver.4500
[2023-06-23 18:15:58.588027 +0000 UTC]  SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbserver.4503": Launching /usr/sbin/fdbserver (29361) for fdbserver.450

// native journalctl
# /usr/bin/journalctl --unit foundationdb --since "2023-06-23 18:15:58" --until "2023-06-23 18:15:59" -n 10
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Watching conf file /etc/foundationdb/foundationdb.conf
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Watching conf dir /etc/foundationdb/ (6)
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Loading configuration /etc/foundationdb/foundationdb.conf
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Found new configuration for fdbserver.4500
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Found new configuration for fdbserver.4503
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Updated configuration for backup_agent.1
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Killing process 29265
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbmonitor": Killing process 29264
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbserver.4500": Launching /usr/sbin/fdbserver (29360) for fdbserver.4500
Jun 23 18:15:58 SDP_DevVM-pchu fdbmonitor[1503]: LogGroup="default" Process="fdbserver.4503": Launching /usr/sbin/fdbserver (29361) for fdbserver.4503

Case 2: set unit, tail and output format

// sanssh
# ./sanssh --targets=localhost sysinfo  journalctl  -unit boot.mount -output json-pretty -tail 1
{
        "CODE_FILE": "src/core/unit.c",
        "CODE_FUNCTION": "unit_status_log_starting_stopping_reloading",
        "CODE_LINE": "1439",
        "MESSAGE": "Mounting /boot...",
        "MESSAGE_ID": "7d4958e842da4a758f6c1cdc7b36dcc5",
        "PRIORITY": "6",
        "SYSLOG_FACILITY": "3",
        "SYSLOG_IDENTIFIER": "systemd",
        "UNIT": "boot.mount",
        "_BOOT_ID": "41248570a6c54ec9b843acbc7fba97e0",
        "_CAP_EFFECTIVE": "1ffffffffff",
        "_CMDLINE": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22",
        "_COMM": "systemd",
        "_EXE": "/usr/lib/systemd/systemd",
        "_GID": "0",
        "_HOSTNAME": "localhost.localdomain",
        "_MACHINE_ID": "6cb5ed28584f4c4d8cdad5b612b94ab7",
        "_PID": "1",
        "_SOURCE_REALTIME_TIMESTAMP": "1687391641745520",
        "_SYSTEMD_CGROUP": "/",
        "_TRANSPORT": "journal",
        "_UID": "0",
        "__CURSOR": "s=6c11b383c7f24cc6995cab9e3a6303e1;i=261;b=41248570a6c54ec9b843acbc7fba97e0;m=44b23d;t=5feac7b6738de;x=a031ed549350a94",
        "__MONOTONIC_TIMESTAMP": "4502077",
        "__REALTIME_TIMESTAMP": "1687391641745630"
}

// native journalctl 
# /usr/bin/journalctl --unit boot.mount --output json-pretty --lines 1
{
	"__CURSOR" : "s=6c11b383c7f24cc6995cab9e3a6303e1;i=261;b=41248570a6c54ec9b843acbc7fba97e0;m=44b23d;t=5feac7b6738de;x=a031ed549350a94",
	"__REALTIME_TIMESTAMP" : "1687391641745630",
	"__MONOTONIC_TIMESTAMP" : "4502077",
	"_BOOT_ID" : "41248570a6c54ec9b843acbc7fba97e0",
	"PRIORITY" : "6",
	"_UID" : "0",
	"_GID" : "0",
	"_MACHINE_ID" : "6cb5ed28584f4c4d8cdad5b612b94ab7",
	"_HOSTNAME" : "localhost.localdomain",
	"SYSLOG_FACILITY" : "3",
	"SYSLOG_IDENTIFIER" : "systemd",
	"_TRANSPORT" : "journal",
	"_CAP_EFFECTIVE" : "1ffffffffff",
	"_PID" : "1",
	"_COMM" : "systemd",
	"_EXE" : "/usr/lib/systemd/systemd",
	"_SYSTEMD_CGROUP" : "/",
	"CODE_FILE" : "src/core/unit.c",
	"CODE_LINE" : "1439",
	"CODE_FUNCTION" : "unit_status_log_starting_stopping_reloading",
	"MESSAGE_ID" : "7d4958e842da4a758f6c1cdc7b36dcc5",
	"_CMDLINE" : "/usr/lib/systemd/systemd --switched-root --system --deserialize 22",
	"UNIT" : "boot.mount",
	"MESSAGE" : "Mounting /boot...",
	"_SOURCE_REALTIME_TIMESTAMP" : "1687391641745520"
}

@sfc-gh-pchu sfc-gh-pchu marked this pull request as ready for review August 7, 2023 23:51
services/sysinfo/client/client.go Outdated Show resolved Hide resolved
services/sysinfo/client/client.go Outdated Show resolved Hide resolved
services/sysinfo/client/client.go Outdated Show resolved Hide resolved
services/sysinfo/client/client.go Outdated Show resolved Hide resolved
services/sysinfo/client/client.go Outdated Show resolved Hide resolved
services/sysinfo/client/client.go Show resolved Hide resolved
services/sysinfo/server/sysinfo_linux.go Outdated Show resolved Hide resolved
services/util/util.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@sfc-gh-ssudakovich sfc-gh-ssudakovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other then the comment, LGTM

services/sysinfo/client/client.go Outdated Show resolved Hide resolved
services/sysinfo/server/sysinfo.go Outdated Show resolved Hide resolved
@sfc-gh-pchu sfc-gh-pchu enabled auto-merge (squash) August 10, 2023 23:17
@sfc-gh-pchu sfc-gh-pchu merged commit cf30e23 into main Aug 10, 2023
3 checks passed
@sfc-gh-pchu sfc-gh-pchu deleted the pchu-add-journalctl-1 branch August 10, 2023 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants