Skip to content

Commit

Permalink
Added CLI command logging
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed May 23, 2024
1 parent 5c77850 commit c4728db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Expected: June 2024

### New features

* Added CLI command logging
* Added split config data into multi-datastore
* Added priority for NB sockets
* Added session kill
Expand Down
23 changes: 23 additions & 0 deletions src/controller_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,27 @@ static clixon_plugin_api api = {
#endif
};

/*! CLIgen history callback function, each added command makes a callback
*
* Could be used for logging all CLI commands for example, or just mirroring the history file
* Note this is not exactly the same as the history command file, since it filters equal
* commands
* @param[in] h CLIgen handle
* @param[in] cmd CLI command. Do not modify or free
* @param[in] arg Argument given when registering
* @retval 0 OK
* @retval -1 Error
*/
static int
cli_history_cb(cligen_handle ch,
char *cmd,
void *arg)
{
clixon_handle h = arg;

return clixon_log(h, LOG_INFO, "command(%s): %s", clicon_username_get(h), cmd);
}

/*! CLI plugin initialization
*
* @param[in] h Clixon handle
Expand Down Expand Up @@ -701,6 +722,8 @@ clixon_plugin_init(clixon_handle h)
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
cligen_tree_resolve_wrapper_set(cli_cligen(h), controller_treeref_wrap, NULL);
}
/* Log CLI commands */
cligen_hist_fn_set(cli_cligen(h), cli_history_cb, h);
return &api;
done:
return NULL;
Expand Down

0 comments on commit c4728db

Please sign in to comment.