cmdbox 0.5.1.2__py3-none-any.whl → 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cmdbox might be problematic. Click here for more details.
- cmdbox/app/app.py +4 -2
- cmdbox/app/auth/signin.py +634 -631
- cmdbox/app/client.py +10 -10
- cmdbox/app/common.py +50 -6
- cmdbox/app/commons/convert.py +9 -0
- cmdbox/app/commons/module.py +113 -113
- cmdbox/app/commons/redis_client.py +40 -29
- cmdbox/app/edge.py +4 -4
- cmdbox/app/features/cli/audit_base.py +138 -0
- cmdbox/app/features/cli/cmdbox_audit_createdb.py +224 -0
- cmdbox/app/features/cli/cmdbox_audit_delete.py +308 -0
- cmdbox/app/features/cli/cmdbox_audit_search.py +416 -0
- cmdbox/app/features/cli/cmdbox_audit_write.py +247 -0
- cmdbox/app/features/cli/cmdbox_client_file_copy.py +207 -207
- cmdbox/app/features/cli/cmdbox_client_file_download.py +207 -207
- cmdbox/app/features/cli/cmdbox_client_file_list.py +193 -193
- cmdbox/app/features/cli/cmdbox_client_file_mkdir.py +191 -191
- cmdbox/app/features/cli/cmdbox_client_file_move.py +199 -199
- cmdbox/app/features/cli/cmdbox_client_file_remove.py +190 -190
- cmdbox/app/features/cli/cmdbox_client_file_rmdir.py +190 -190
- cmdbox/app/features/cli/cmdbox_client_file_upload.py +212 -212
- cmdbox/app/features/cli/cmdbox_client_server_info.py +166 -166
- cmdbox/app/features/cli/cmdbox_server_list.py +88 -88
- cmdbox/app/features/cli/cmdbox_server_stop.py +138 -138
- cmdbox/app/features/web/cmdbox_web_audit.py +81 -0
- cmdbox/app/features/web/cmdbox_web_audit_metrics.py +72 -0
- cmdbox/app/features/web/cmdbox_web_del_cmd.py +2 -0
- cmdbox/app/features/web/cmdbox_web_del_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_do_signin.py +12 -2
- cmdbox/app/features/web/cmdbox_web_do_signout.py +1 -0
- cmdbox/app/features/web/cmdbox_web_exec_cmd.py +31 -2
- cmdbox/app/features/web/cmdbox_web_exec_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_filer download.py +43 -42
- cmdbox/app/features/web/cmdbox_web_filer.py +1 -0
- cmdbox/app/features/web/cmdbox_web_filer_upload.py +65 -64
- cmdbox/app/features/web/cmdbox_web_gui.py +166 -165
- cmdbox/app/features/web/cmdbox_web_load_pin.py +43 -43
- cmdbox/app/features/web/cmdbox_web_raw_pipe.py +87 -87
- cmdbox/app/features/web/cmdbox_web_save_cmd.py +1 -0
- cmdbox/app/features/web/cmdbox_web_save_pin.py +42 -42
- cmdbox/app/features/web/cmdbox_web_save_pipe.py +1 -0
- cmdbox/app/features/web/cmdbox_web_user_data.py +58 -0
- cmdbox/app/features/web/cmdbox_web_users.py +12 -0
- cmdbox/app/options.py +788 -601
- cmdbox/app/web.py +7 -1
- cmdbox/extensions/features.yml +23 -0
- cmdbox/extensions/sample_project/sample/app/features/cli/sample_client_time.py +82 -82
- cmdbox/extensions/sample_project/sample/app/features/cli/sample_server_time.py +145 -145
- cmdbox/extensions/user_list.yml +5 -0
- cmdbox/licenses/{LICENSE.Sphinx.8.1.3(BSD License).txt → LICENSE.Sphinx.8.2.3(UNKNOWN).txt} +1 -1
- cmdbox/licenses/LICENSE.argcomplete.3.6.2(Apache Software License).txt +177 -0
- cmdbox/licenses/{LICENSE.babel.2.16.0(BSD License).txt → LICENSE.babel.2.17.0(BSD License).txt } +1 -1
- cmdbox/licenses/{LICENSE.pkginfo.1.10.0(MIT License).txt → LICENSE.charset-normalizer.3.4.1(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.gevent.25.4.1(MIT).txt +25 -0
- cmdbox/licenses/LICENSE.greenlet.3.2.0(MIT AND Python-2.0).txt +30 -0
- cmdbox/licenses/LICENSE.gunicorn.23.0.0(MIT License).txt +23 -0
- cmdbox/licenses/LICENSE.importlib_metadata.8.6.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.nh3.0.2.21(MIT).txt +21 -0
- cmdbox/licenses/{LICENSE.pillow.11.0.0(CMU License (MIT-CMU)).txt → LICENSE.pillow.11.1.0(CMU License (MIT-CMU)).txt } +27 -40
- cmdbox/licenses/LICENSE.pillow.11.2.1(UNKNOWN).txt +1200 -0
- cmdbox/licenses/LICENSE.plyer.2.1.0(MIT License).txt +19 -0
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.50(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.51(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.psycopg-binary.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.psycopg-pool.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.psycopg.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +165 -0
- cmdbox/licenses/LICENSE.pycryptodome.3.22.0(BSD License; Public Domain).txt +61 -0
- cmdbox/licenses/LICENSE.pydantic.2.11.3(MIT License).txt +21 -0
- cmdbox/licenses/LICENSE.pydantic_core.2.33.1(MIT License).txt +21 -0
- cmdbox/licenses/LICENSE.pystray.0.19.5(GNU Lesser General Public License v3 (LGPLv3)).txt +674 -0
- cmdbox/licenses/LICENSE.questionary.2.1.0(MIT License).txt +19 -0
- cmdbox/licenses/LICENSE.roman-numerals-py.3.1.0(CC0 1.0 Universal (CC0 1.0) Public Domain Dedication; Zero-Clause BSD (0BSD)).txt +146 -0
- cmdbox/licenses/{LICENSE.six.1.16.0(MIT License).txt → LICENSE.six.1.17.0(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.starlette.0.46.2(BSD License).txt +27 -0
- cmdbox/licenses/{LICENSE.charset-normalizer.3.4.0(MIT License).txt → LICENSE.typing-inspection.0.4.0(MIT License).txt } +2 -2
- cmdbox/licenses/LICENSE.typing_extensions.4.13.2(UNKNOWN).txt +279 -0
- cmdbox/licenses/LICENSE.tzdata.2025.2(Apache Software License).txt +15 -0
- cmdbox/licenses/LICENSE.urllib3.2.4.0(UNKNOWN).txt +21 -0
- cmdbox/licenses/LICENSE.uvicorn.0.34.1(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.watchfiles.1.0.5(MIT License).txt +21 -0
- cmdbox/licenses/files.txt +49 -38
- cmdbox/logconf_audit.yml +30 -0
- cmdbox/logconf_cmdbox.yml +30 -0
- cmdbox/version.py +2 -2
- cmdbox/web/assets/apexcharts/apexcharts.css +679 -0
- cmdbox/web/assets/apexcharts/apexcharts.min.js +38 -0
- cmdbox/web/assets/cmdbox/audit.js +340 -0
- cmdbox/web/assets/cmdbox/color_mode.css +520 -0
- cmdbox/web/assets/cmdbox/common.js +416 -24
- cmdbox/web/assets/cmdbox/filer_modal.js +1 -1
- cmdbox/web/assets/cmdbox/list_cmd.js +10 -275
- cmdbox/web/assets/cmdbox/list_pipe.js +3 -3
- cmdbox/web/assets/cmdbox/main.js +2 -2
- cmdbox/web/assets/cmdbox/result.js +2 -2
- cmdbox/web/assets/cmdbox/signin.js +2 -2
- cmdbox/web/assets/cmdbox/users.js +19 -20
- cmdbox/web/assets/cmdbox/view_raw.js +1 -1
- cmdbox/web/assets/cmdbox/view_result.js +11 -13
- cmdbox/web/assets/filer/filer.js +2 -2
- cmdbox/web/assets/filer/main.js +2 -2
- cmdbox/web/assets_license_list.txt +4 -1
- cmdbox/web/audit.html +268 -0
- cmdbox/web/filer.html +37 -12
- cmdbox/web/gui.html +36 -53
- cmdbox/web/result.html +24 -3
- cmdbox/web/signin.html +35 -14
- cmdbox/web/users.html +21 -3
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/METADATA +28 -5
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/RECORD +142 -103
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/entry_points.txt +0 -1
- cmdbox/licenses/LICENSE.nh3.0.2.18(MIT).txt +0 -1
- /cmdbox/licenses/{LICENSE.Jinja2.3.1.4(BSD License).txt → LICENSE.Jinja2.3.1.6(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.Pygments.2.18.0(BSD License).txt → LICENSE.Pygments.2.19.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.anyio.4.6.2.post1(MIT License).txt → LICENSE.anyio.4.9.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.argcomplete.3.5.1(Apache Software License).txt → LICENSE.argcomplete.3.6.1(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.certifi.2024.8.30(Mozilla Public License 2.0 (MPL 2.0)).txt → LICENSE.certifi.2025.1.31(Mozilla Public License 2.0 (MPL 2.0)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.click.8.1.7(BSD License).txt → LICENSE.click.8.1.8(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.cryptography.43.0.3(Apache Software License; BSD License).txt → LICENSE.cryptography.44.0.2(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.fastapi.0.115.5(MIT License).txt → LICENSE.fastapi.0.115.12(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.importlib_metadata.8.5.0(Apache Software License).txt → LICENSE.id.1.5.0(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.keyring.25.5.0(MIT License).txt → LICENSE.keyring.25.6.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.more-itertools.10.5.0(MIT License).txt → LICENSE.more-itertools.10.6.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.numpy.2.1.3(BSD License).txt → LICENSE.numpy.2.2.4(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.prettytable.3.12.0(BSD License).txt → LICENSE.prettytable.3.16.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic.2.10.2(MIT License).txt → LICENSE.pydantic.2.11.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic_core.2.27.1(MIT License).txt → LICENSE.pydantic_core.2.33.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.python-dotenv.1.0.1(BSD License).txt → LICENSE.python-dotenv.1.1.0(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.python-multipart.0.0.17(Apache Software License).txt → LICENSE.python-multipart.0.0.20(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.redis.5.2.0(MIT License).txt → LICENSE.redis.5.2.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.rich.13.9.4(MIT License).txt → LICENSE.rich.14.0.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.sphinx-intl.2.3.0(BSD License).txt → LICENSE.sphinx-intl.2.3.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.starlette.0.41.3(BSD License).txt → LICENSE.starlette.0.46.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.tomli.2.1.0(MIT License).txt → LICENSE.tomli.2.2.1(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.twine.5.1.1(Apache Software License).txt → LICENSE.twine.6.1.0(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.typing_extensions.4.12.2(Python Software Foundation License).txt → LICENSE.typing_extensions.4.13.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.urllib3.2.2.3(MIT License).txt → LICENSE.urllib3.2.3.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.uvicorn.0.32.1(BSD License).txt → LICENSE.uvicorn.0.34.0(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.watchfiles.1.0.0(MIT License).txt → LICENSE.watchfiles.1.0.4(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.websockets.14.1(BSD License).txt → LICENSE.websockets.15.0.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.zope.interface.7.1.1(Zope Public License).txt → LICENSE.zope.interface.7.2(Zope Public License).txt} +0 -0
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/LICENSE +0 -0
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/WHEEL +0 -0
- {cmdbox-0.5.1.2.dist-info → cmdbox-0.5.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
from cmdbox.app import common, client
|
|
2
|
+
from cmdbox.app.commons import convert, redis_client
|
|
3
|
+
from cmdbox.app.features.cli import audit_base
|
|
4
|
+
from cmdbox.app.options import Options
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from psycopg.rows import dict_row
|
|
7
|
+
from typing import Dict, Any, Tuple, List, Union
|
|
8
|
+
import argparse
|
|
9
|
+
import logging
|
|
10
|
+
import json
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AuditSearch(audit_base.AuditBase):
|
|
15
|
+
def get_mode(self) -> Union[str, List[str]]:
|
|
16
|
+
"""
|
|
17
|
+
この機能のモードを返します
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Union[str, List[str]]: モード
|
|
21
|
+
"""
|
|
22
|
+
return 'audit'
|
|
23
|
+
|
|
24
|
+
def get_cmd(self):
|
|
25
|
+
"""
|
|
26
|
+
この機能のコマンドを返します
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
str: コマンド
|
|
30
|
+
"""
|
|
31
|
+
return 'search'
|
|
32
|
+
|
|
33
|
+
def get_option(self):
|
|
34
|
+
"""
|
|
35
|
+
この機能のオプションを返します
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Dict[str, Any]: オプション
|
|
39
|
+
"""
|
|
40
|
+
opt = super().get_option()
|
|
41
|
+
opt['discription_ja'] = "監査ログを検索します。"
|
|
42
|
+
opt['discription_en'] = "Search the audit log."
|
|
43
|
+
opt['choice'] += [
|
|
44
|
+
dict(opt="select", type=Options.T_DICT, default=None, required=False, multi=True, hide=False,
|
|
45
|
+
choice=dict(key=['']+self.TBL_COLS, val=['-','count','sum','avg','min','max']),
|
|
46
|
+
discription_ja="取得項目を指定します。指定しない場合は全ての項目を取得します。",
|
|
47
|
+
discription_en="Specify the items to be retrieved. If not specified, all items are acquired."),
|
|
48
|
+
dict(opt="select_date_format", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=['']+self.DT_FMT,
|
|
49
|
+
discription_ja="取得項目の日時のフォーマットを指定します。",
|
|
50
|
+
discription_en="Specifies the format of the date and time of the acquisition item."),
|
|
51
|
+
dict(opt="filter_audit_type", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=['']+Options.AUDITS,
|
|
52
|
+
discription_ja="フィルタ条件の監査の種類を指定します。",
|
|
53
|
+
discription_en="Specifies the type of audit for the filter condition."),
|
|
54
|
+
dict(opt="filter_clmsg_id", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
55
|
+
discription_ja="フィルタ条件のクライアントのメッセージIDを指定します。",
|
|
56
|
+
discription_en="Specify the message ID of the client for the filter condition."),
|
|
57
|
+
dict(opt="filter_clmsg_sdate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
58
|
+
discription_ja="フィルタ条件のクライアントのメッセージ発生日時(開始)を指定します。",
|
|
59
|
+
discription_en="Specify the date and time (start) when the message occurred for the client in the filter condition."),
|
|
60
|
+
dict(opt="filter_clmsg_edate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
61
|
+
discription_ja="フィルタ条件のクライアントのメッセージ発生日時(終了)を指定します。",
|
|
62
|
+
discription_en="Specify the date and time (end) when the message occurred for the client in the filter condition."),
|
|
63
|
+
dict(opt="filter_clmsg_src", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
64
|
+
discription_ja="フィルタ条件のクライアントのメッセージの発生源を指定します。LIKE検索を行います。",
|
|
65
|
+
discription_en="Specifies the source of the message for the client in the filter condition; performs a LIKE search."),
|
|
66
|
+
dict(opt="filter_clmsg_title", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
67
|
+
discription_ja="フィルタ条件のクライアントのメッセージタイトルを指定します。LIKE検索を行います。",
|
|
68
|
+
discription_en="Specifies the message title of the client for the filter condition; a LIKE search is performed."),
|
|
69
|
+
dict(opt="filter_clmsg_user", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
70
|
+
discription_ja="フィルタ条件のクライアントのメッセージの発生させたユーザーを指定します。LIKE検索を行います。",
|
|
71
|
+
discription_en="Specifies the user who generated the message for the client in the filter condition; performs a LIKE search."),
|
|
72
|
+
dict(opt="filter_clmsg_body", type=Options.T_DICT, default=None, required=False, multi=True, hide=False, choice=None,
|
|
73
|
+
discription_ja="フィルタ条件のクライアントのメッセージの本文を辞書形式で指定します。LIKE検索を行います。",
|
|
74
|
+
discription_en="Specifies the body of the client's message in the filter condition in dictionary format; performs a LIKE search."),
|
|
75
|
+
dict(opt="filter_clmsg_tag", type=Options.T_STR, default=None, required=False, multi=True, hide=False, choice=None,
|
|
76
|
+
discription_ja="フィルタ条件のクライアントのメッセージのタグを指定します。",
|
|
77
|
+
discription_en="Specifies the tag of the client's message in the filter condition."),
|
|
78
|
+
dict(opt="filter_svmsg_id", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=None,
|
|
79
|
+
discription_ja="フィルタ条件のサーバーのメッセージIDを指定します。",
|
|
80
|
+
discription_en="Specify the message ID of the server for the filter condition."),
|
|
81
|
+
dict(opt="filter_svmsg_sdate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
82
|
+
discription_ja="フィルタ条件のサーバーのメッセージ発生日時(開始)を指定します。",
|
|
83
|
+
discription_en="Specify the date and time (start) when the message occurred for the server in the filter condition."),
|
|
84
|
+
dict(opt="filter_svmsg_edate", type=Options.T_DATETIME, default=None, required=False, multi=False, hide=False, choice=None,
|
|
85
|
+
discription_ja="フィルタ条件のサーバーのメッセージ発生日時(終了)を指定します。",
|
|
86
|
+
discription_en="Specify the date and time (end) when the message occurred for the server in the filter condition."),
|
|
87
|
+
dict(opt="groupby", type=Options.T_STR, default=None, required=False, multi=True, hide=False, choice=['']+self.TBL_COLS,
|
|
88
|
+
discription_ja="グループ化項目を指定します。",
|
|
89
|
+
discription_en="Specify grouping items."),
|
|
90
|
+
dict(opt="groupby_date_format", type=Options.T_STR, default=None, required=False, multi=False, hide=False, choice=['']+self.DT_FMT,
|
|
91
|
+
discription_ja="グループ化項目の日時のフォーマットを指定します。",
|
|
92
|
+
discription_en="Specifies the format of the date and time of the grouping item."),
|
|
93
|
+
dict(opt="sort", type=Options.T_DICT, default=None, required=False, multi=True, hide=False, choice=dict(key=['']+self.TBL_COLS, val=['', 'ASC', 'DESC']),
|
|
94
|
+
discription_ja="ソート項目を指定します。",
|
|
95
|
+
discription_en="Specify the sort item."),
|
|
96
|
+
dict(opt="offset", type=Options.T_INT, default=0, required=False, multi=False, hide=False, choice=None,
|
|
97
|
+
discription_ja="取得する行の開始位置を指定します。",
|
|
98
|
+
discription_en="Specifies the starting position of the row to be retrieved."),
|
|
99
|
+
dict(opt="limit", type=Options.T_INT, default=100, required=False, multi=False, hide=False, choice=None,
|
|
100
|
+
discription_ja="取得する行数を指定します。",
|
|
101
|
+
discription_en="Specifies the number of rows to retrieve."),
|
|
102
|
+
]
|
|
103
|
+
return opt
|
|
104
|
+
|
|
105
|
+
def get_svcmd(self):
|
|
106
|
+
"""
|
|
107
|
+
この機能のサーバー側のコマンドを返します
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
str: サーバー側のコマンド
|
|
111
|
+
"""
|
|
112
|
+
return 'audit_search'
|
|
113
|
+
|
|
114
|
+
def apprun(self, logger:logging.Logger, args:argparse.Namespace, tm:float, pf:List[Dict[str, float]]=[]) -> Tuple[int, Dict[str, Any], Any]:
|
|
115
|
+
"""
|
|
116
|
+
この機能の実行を行います
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
logger (logging.Logger): ロガー
|
|
120
|
+
args (argparse.Namespace): 引数
|
|
121
|
+
tm (float): 実行開始時間
|
|
122
|
+
pf (List[Dict[str, float]]): 呼出元のパフォーマンス情報
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
Tuple[int, Dict[str, Any], Any]: 終了コード, 結果, オブジェクト
|
|
126
|
+
"""
|
|
127
|
+
if args.svname is None:
|
|
128
|
+
msg = dict(warn=f"Please specify the --svname option.")
|
|
129
|
+
common.print_format(msg, args.format, tm, None, False, pf=pf)
|
|
130
|
+
return 1, msg, None
|
|
131
|
+
|
|
132
|
+
select_str = json.dumps(args.select, default=common.default_json_enc, ensure_ascii=False) if getattr(args, 'select', None) else '{}'
|
|
133
|
+
select_b64 = convert.str2b64str(select_str)
|
|
134
|
+
select_date_format_b64 = convert.str2b64str(getattr(args, 'select_date_format', None))
|
|
135
|
+
groupby_str = json.dumps(args.groupby, default=common.default_json_enc, ensure_ascii=False) if getattr(args, 'groupby', None) else '[]'
|
|
136
|
+
groupby_b64 = convert.str2b64str(groupby_str)
|
|
137
|
+
groupby_date_format_b64 = convert.str2b64str(getattr(args, 'groupby_date_format', None))
|
|
138
|
+
args.sort = args.sort if getattr(args, 'sort', {}) else {}
|
|
139
|
+
args.sort = args.sort if isinstance(args.sort, dict) else {str(args.sort): 'DESC'}
|
|
140
|
+
sort_str = json.dumps(args.sort, default=common.default_json_enc, ensure_ascii=False)
|
|
141
|
+
sort_b64 = convert.str2b64str(sort_str)
|
|
142
|
+
offset = getattr(args, 'offset', None)
|
|
143
|
+
limit = getattr(args, 'limit', None)
|
|
144
|
+
filter_audit_type_b64 = convert.str2b64str(getattr(args, 'filter_audit_type', None))
|
|
145
|
+
filter_clmsg_id_b64 = convert.str2b64str(getattr(args, 'filter_clmsg_id', None))
|
|
146
|
+
filter_clmsg_sdate = args.filter_clmsg_sdate+common.get_tzoffset_str() if getattr(args, 'filter_clmsg_sdate', None) else None
|
|
147
|
+
filter_clmsg_sdate_b64 = convert.str2b64str(filter_clmsg_sdate)
|
|
148
|
+
filter_clmsg_edate = args.filter_clmsg_edate+common.get_tzoffset_str() if getattr(args, 'filter_clmsg_edate', None) else None
|
|
149
|
+
filter_clmsg_edate_b64 = convert.str2b64str(filter_clmsg_edate)
|
|
150
|
+
filter_clmsg_src_b64 = convert.str2b64str(getattr(args, 'filter_clmsg_src', None))
|
|
151
|
+
filter_clmsg_title_b64 = convert.str2b64str(getattr(args, 'filter_clmsg_title', None))
|
|
152
|
+
filter_clmsg_user_b64 = convert.str2b64str(getattr(args, 'filter_clmsg_user', None))
|
|
153
|
+
filter_clmsg_body_str = json.dumps(args.filter_clmsg_body, default=common.default_json_enc, ensure_ascii=False) if getattr(args, 'filter_clmsg_body', None) else '{}'
|
|
154
|
+
filter_clmsg_body_b64 = convert.str2b64str(filter_clmsg_body_str)
|
|
155
|
+
filter_clmsg_tag_str = json.dumps(args.filter_clmsg_tag, default=common.default_json_enc, ensure_ascii=False) if getattr(args, 'filter_clmsg_tag', None) else '[]'
|
|
156
|
+
filter_clmsg_tag_b64 = convert.str2b64str(filter_clmsg_tag_str)
|
|
157
|
+
filter_svmsg_id_b64 = convert.str2b64str(getattr(args, 'filter_svmsg_id', None))
|
|
158
|
+
filter_svmsg_sdate_b64 = convert.str2b64str(getattr(args, 'filter_svmsg_sdate', None))
|
|
159
|
+
filter_svmsg_edate_b64 = convert.str2b64str(getattr(args, 'filter_svmsg_edate', None))
|
|
160
|
+
pg_enabled = args.pg_enabled if getattr(args, 'pg_enabled', False) and isinstance(args.pg_enabled, bool) else False
|
|
161
|
+
pg_host_b64 = convert.str2b64str(getattr(args, 'pg_host', None))
|
|
162
|
+
pg_port = args.pg_port if getattr(args, 'pg_port', 5432) and isinstance(args.pg_port, int) else None
|
|
163
|
+
pg_user_b64 = convert.str2b64str(getattr(args, 'pg_user', None))
|
|
164
|
+
pg_password_b64 = convert.str2b64str(getattr(args, 'pg_password', None))
|
|
165
|
+
pg_dbname_b64 = convert.str2b64str(getattr(args, 'pg_dbname', None))
|
|
166
|
+
|
|
167
|
+
cl = client.Client(logger, redis_host=args.host, redis_port=args.port, redis_password=args.password, svname=args.svname)
|
|
168
|
+
ret = cl.redis_cli.send_cmd(self.get_svcmd(),
|
|
169
|
+
[select_b64, select_date_format_b64, groupby_b64, groupby_date_format_b64,
|
|
170
|
+
sort_b64, str(offset), str(limit),
|
|
171
|
+
filter_audit_type_b64, filter_clmsg_id_b64, filter_clmsg_sdate_b64, filter_clmsg_edate_b64,
|
|
172
|
+
filter_clmsg_src_b64, filter_clmsg_title_b64, filter_clmsg_user_b64, filter_clmsg_body_b64,
|
|
173
|
+
filter_clmsg_tag_b64, filter_svmsg_id_b64, filter_svmsg_sdate_b64, filter_svmsg_edate_b64,
|
|
174
|
+
pg_enabled, pg_host_b64, pg_port, pg_user_b64, pg_password_b64, pg_dbname_b64],
|
|
175
|
+
retry_count=args.retry_count, retry_interval=args.retry_interval, timeout=args.timeout)
|
|
176
|
+
common.print_format(ret, getattr(args, 'format', False), tm, None, False, pf=pf)
|
|
177
|
+
|
|
178
|
+
if 'success' not in ret:
|
|
179
|
+
return 1, ret, cl
|
|
180
|
+
|
|
181
|
+
if 'data' in ret['success']:
|
|
182
|
+
for row in ret['success']['data']:
|
|
183
|
+
try:
|
|
184
|
+
row['clmsg_tag'] = json.loads(row['clmsg_tag'])
|
|
185
|
+
except:
|
|
186
|
+
pass
|
|
187
|
+
try:
|
|
188
|
+
row['clmsg_body'] = json.loads(row['clmsg_body'])
|
|
189
|
+
except:
|
|
190
|
+
pass
|
|
191
|
+
|
|
192
|
+
return 0, ret, cl
|
|
193
|
+
|
|
194
|
+
def is_cluster_redirect(self):
|
|
195
|
+
"""
|
|
196
|
+
クラスター宛のメッセージの場合、メッセージを転送するかどうかを返します
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
bool: メッセージを転送する場合はTrue
|
|
200
|
+
"""
|
|
201
|
+
return False
|
|
202
|
+
|
|
203
|
+
def svrun(self, data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient, msg:List[str],
|
|
204
|
+
sessions:Dict[str, Dict[str, Any]]) -> int:
|
|
205
|
+
"""
|
|
206
|
+
この機能のサーバー側の実行を行います
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
data_dir (Path): データディレクトリ
|
|
210
|
+
logger (logging.Logger): ロガー
|
|
211
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
212
|
+
msg (List[str]): 受信メッセージ
|
|
213
|
+
sessions (Dict[str, Dict[str, Any]]): セッション情報
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
int: 終了コード
|
|
217
|
+
"""
|
|
218
|
+
select = json.loads(convert.b64str2str(msg[2]))
|
|
219
|
+
select_date_format = convert.b64str2str(msg[3])
|
|
220
|
+
groupby = json.loads(convert.b64str2str(msg[4]))
|
|
221
|
+
groupby_date_format = convert.b64str2str(msg[5])
|
|
222
|
+
sort = json.loads(convert.b64str2str(msg[6]))
|
|
223
|
+
offset = int(msg[7]) if msg[7] else 0
|
|
224
|
+
limit = int(msg[8]) if msg[8] else 100
|
|
225
|
+
|
|
226
|
+
filter_audit_type = convert.b64str2str(msg[9])
|
|
227
|
+
filter_clmsg_id = convert.b64str2str(msg[10])
|
|
228
|
+
filter_clmsg_sdate = convert.b64str2str(msg[11])
|
|
229
|
+
filter_clmsg_edate = convert.b64str2str(msg[12])
|
|
230
|
+
filter_clmsg_src = convert.b64str2str(msg[13])
|
|
231
|
+
filter_clmsg_title = convert.b64str2str(msg[14])
|
|
232
|
+
filter_clmsg_user = convert.b64str2str(msg[15])
|
|
233
|
+
body = json.loads(convert.b64str2str(msg[16]))
|
|
234
|
+
tags = json.loads(convert.b64str2str(msg[17]))
|
|
235
|
+
filter_svmsg_id = convert.b64str2str(msg[18])
|
|
236
|
+
filter_svmsg_sdate = convert.b64str2str(msg[19])
|
|
237
|
+
filter_svmsg_edate = convert.b64str2str(msg[20])
|
|
238
|
+
pg_enabled = True if msg[21]=='True' else False
|
|
239
|
+
pg_host = convert.b64str2str(msg[22])
|
|
240
|
+
pg_port = int(msg[23]) if msg[23]!='None' else None
|
|
241
|
+
pg_user = convert.b64str2str(msg[24])
|
|
242
|
+
pg_password = convert.b64str2str(msg[25])
|
|
243
|
+
pg_dbname = convert.b64str2str(msg[26])
|
|
244
|
+
st = self.search(msg[1], select, select_date_format, groupby, groupby_date_format,
|
|
245
|
+
sort, offset, limit,
|
|
246
|
+
filter_audit_type, filter_clmsg_id, filter_clmsg_sdate, filter_clmsg_edate,
|
|
247
|
+
filter_clmsg_src, filter_clmsg_title, filter_clmsg_user, body, tags,
|
|
248
|
+
filter_svmsg_id, filter_svmsg_sdate, filter_svmsg_edate,
|
|
249
|
+
pg_enabled, pg_host, pg_port, pg_user, pg_password, pg_dbname,
|
|
250
|
+
data_dir, logger, redis_cli)
|
|
251
|
+
return st
|
|
252
|
+
|
|
253
|
+
def search(self, reskey:str, select:Dict[str, str], select_date_format:str, groupby:List[str], groupby_date_format:str, sort:Dict[str, str], offset:int, limit:int,
|
|
254
|
+
filter_audit_type:str, filter_clmsg_id:str, filter_clmsg_sdate:str, filter_clmsg_edate:str,
|
|
255
|
+
filter_clmsg_src:str, filter_clmsg_title:str, filter_clmsg_user:str, filter_clmsg_body:Dict[str, Any],
|
|
256
|
+
filter_clmsg_tags:List[str], filter_svmsg_id:str, filter_svmsg_sdate:str, filter_svmsg_edate:str,
|
|
257
|
+
pg_enabled:bool, pg_host:str, pg_port:int, pg_user:str, pg_password:str, pg_dbname:str,
|
|
258
|
+
data_dir:Path, logger:logging.Logger, redis_cli:redis_client.RedisClient) -> int:
|
|
259
|
+
"""
|
|
260
|
+
監査ログを検索する
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
reskey (str): レスポンスキー
|
|
264
|
+
select (Dict[str, str]): 取得項目
|
|
265
|
+
select_date_format (str): 取得項目の日時フォーマット
|
|
266
|
+
groupby (List[str]): グループ化項目
|
|
267
|
+
groupby_date_format (str): グループ化項目の日時フォーマット
|
|
268
|
+
sort (Dict[str, str]): ソート条件
|
|
269
|
+
offset (int): 取得する行の開始位置
|
|
270
|
+
limit (int): 取得する行数
|
|
271
|
+
filter_audit_type (str): 監査の種類
|
|
272
|
+
filter_clmsg_id (str): クライアントメッセージID
|
|
273
|
+
filter_clmsg_sdate (str): クライアントメッセージ発生日時(開始)
|
|
274
|
+
filter_clmsg_edate (str): クライアントメッセージ発生日時(終了)
|
|
275
|
+
filter_clmsg_src (str): クライアントメッセージの発生源
|
|
276
|
+
filter_clmsg_title (str): クライアントメッセージのタイトル
|
|
277
|
+
filter_clmsg_user (str): クライアントメッセージの発生させたユーザー
|
|
278
|
+
filter_clmsg_body (Dict[str, Any]): クライアントメッセージの本文
|
|
279
|
+
filter_clmsg_tags (List[str]): クライアントメッセージのタグ
|
|
280
|
+
filter_svmsg_id (str): サーバーメッセージID
|
|
281
|
+
filter_svmsg_sdate (str): サーバーメッセージ発生日時(開始)
|
|
282
|
+
filter_svmsg_edate (str): サーバーメッセージ発生日時(終了)
|
|
283
|
+
pg_enabled (bool): PostgreSQLを使用する場合はTrue
|
|
284
|
+
pg_host (str): PostgreSQLホスト
|
|
285
|
+
pg_port (int): PostgreSQLポート
|
|
286
|
+
pg_user (str): PostgreSQLユーザー
|
|
287
|
+
pg_password (str): PostgreSQLパスワード
|
|
288
|
+
pg_dbname (str): PostgreSQLデータベース名
|
|
289
|
+
data_dir (Path): データディレクトリ
|
|
290
|
+
logger (logging.Logger): ロガー
|
|
291
|
+
redis_cli (redis_client.RedisClient): Redisクライアント
|
|
292
|
+
|
|
293
|
+
Returns:
|
|
294
|
+
int: レスポンスコード
|
|
295
|
+
"""
|
|
296
|
+
def _date_format(pg_enabled, col, date_format):
|
|
297
|
+
if col not in ['clmsg_date', 'svmsg_date']:
|
|
298
|
+
return col
|
|
299
|
+
if pg_enabled:
|
|
300
|
+
if date_format == '%u':
|
|
301
|
+
return f"to_char({col}, 'D')"
|
|
302
|
+
elif date_format == '%m':
|
|
303
|
+
return f"to_char({col}, 'MM')"
|
|
304
|
+
elif date_format == '%Y':
|
|
305
|
+
return f"to_char({col}, 'YYYY')"
|
|
306
|
+
elif date_format == '%Y/%m':
|
|
307
|
+
return f"to_char({col}, 'YYYY/MM')"
|
|
308
|
+
elif date_format == '%Y/%m/%d':
|
|
309
|
+
return f"to_char({col}, 'YYYY/MM/DD')"
|
|
310
|
+
elif date_format == '%Y/%m/%d %H':
|
|
311
|
+
return f"to_char({col}, 'YYYY/MM/DD HH24')"
|
|
312
|
+
elif date_format == '%Y/%m/%d %H:%M':
|
|
313
|
+
return f"to_char({col}, 'YYYY/MM/DD HH24:MI')"
|
|
314
|
+
else:
|
|
315
|
+
return col
|
|
316
|
+
else:
|
|
317
|
+
if date_format is not None and date_format != '':
|
|
318
|
+
return f"strftime('{date_format}', {col})"
|
|
319
|
+
else:
|
|
320
|
+
return col
|
|
321
|
+
try:
|
|
322
|
+
with self.initdb(data_dir, logger, pg_enabled, pg_host, pg_port, pg_user, pg_password, pg_dbname) as conn:
|
|
323
|
+
def dict_factory(cursor, row):
|
|
324
|
+
return {col[0]: row[idx] for idx, col in enumerate(cursor.description)}
|
|
325
|
+
conn.row_factory = dict_row if pg_enabled else dict_factory
|
|
326
|
+
cursor = conn.cursor()
|
|
327
|
+
try:
|
|
328
|
+
select = {k:v for k,v in select.items() if k != ''} if select else None
|
|
329
|
+
select = select if select and len(select)>0 else {k:'-' for k in self.TBL_COLS}
|
|
330
|
+
if pg_enabled:
|
|
331
|
+
toz = common.get_tzoffset_str()
|
|
332
|
+
sel = {}
|
|
333
|
+
for k,v in select.items():
|
|
334
|
+
if k in ['clmsg_date', 'svmsg_date']:
|
|
335
|
+
sel[f"{k} AT TIME ZONE INTERVAL '{toz}' as {k}"] = v
|
|
336
|
+
else:
|
|
337
|
+
sel[k] = v
|
|
338
|
+
select = sel
|
|
339
|
+
sql = []
|
|
340
|
+
for k,v in select.items():
|
|
341
|
+
if v in ['count', 'sum', 'avg', 'min', 'max']:
|
|
342
|
+
sql.append(f'{v}({_date_format(pg_enabled, k, select_date_format)}) AS {k}')
|
|
343
|
+
else:
|
|
344
|
+
sql.append(f'{_date_format(pg_enabled, k, select_date_format)} AS {k}')
|
|
345
|
+
sql = f"SELECT {','.join(sql)} FROM audit"
|
|
346
|
+
params = []
|
|
347
|
+
where = []
|
|
348
|
+
if filter_audit_type and filter_audit_type != 'None':
|
|
349
|
+
where.append(f'audit_type={"%s" if pg_enabled else "?"}')
|
|
350
|
+
params.append(filter_audit_type)
|
|
351
|
+
if filter_clmsg_id and filter_clmsg_id != 'None':
|
|
352
|
+
where.append(f'clmsg_id={"%s" if pg_enabled else "?"}')
|
|
353
|
+
params.append(filter_clmsg_id)
|
|
354
|
+
if filter_clmsg_sdate and filter_clmsg_sdate != 'None':
|
|
355
|
+
where.append(f'clmsg_date>={"%s" if pg_enabled else "?"}')
|
|
356
|
+
params.append(filter_clmsg_sdate)
|
|
357
|
+
if filter_clmsg_edate and filter_clmsg_edate != 'None':
|
|
358
|
+
where.append(f'clmsg_date<={"%s" if pg_enabled else "?"}')
|
|
359
|
+
params.append(filter_clmsg_edate)
|
|
360
|
+
if filter_clmsg_src and filter_clmsg_src != 'None':
|
|
361
|
+
where.append(f'clmsg_src LIKE {"%s" if pg_enabled else "?"}')
|
|
362
|
+
params.append(filter_clmsg_src)
|
|
363
|
+
if filter_clmsg_title and filter_clmsg_title != 'None':
|
|
364
|
+
where.append(f'clmsg_title LIKE {"%s" if pg_enabled else "?"}')
|
|
365
|
+
params.append(filter_clmsg_title)
|
|
366
|
+
if filter_clmsg_user and filter_clmsg_user != 'None':
|
|
367
|
+
where.append(f'clmsg_user LIKE {"%s" if pg_enabled else "?"}')
|
|
368
|
+
params.append(filter_clmsg_user)
|
|
369
|
+
if filter_clmsg_body:
|
|
370
|
+
if sys.version_info[0] < 3 or sys.version_info[0] >= 3 and sys.version_info[1] < 10:
|
|
371
|
+
raise RuntimeError("Python 3.10 or later is required for JSON support.")
|
|
372
|
+
for key, value in filter_clmsg_body.items():
|
|
373
|
+
where.append(f"clmsg_body->>'{key}' LIKE {'%s' if pg_enabled else '?'}")
|
|
374
|
+
params.append(value)
|
|
375
|
+
if filter_clmsg_tags:
|
|
376
|
+
for tag in filter_clmsg_tags:
|
|
377
|
+
where.append(f"clmsg_tag like {'%s' if pg_enabled else '?'}")
|
|
378
|
+
params.append(f'%{tag}%')
|
|
379
|
+
if filter_svmsg_id and filter_svmsg_id != 'None':
|
|
380
|
+
where.append(f'svmsg_id={"%s" if pg_enabled else "?"}')
|
|
381
|
+
params.append(filter_svmsg_id)
|
|
382
|
+
if filter_svmsg_sdate and filter_svmsg_sdate != 'None':
|
|
383
|
+
where.append(f'svmsg_date>={"%s" if pg_enabled else "?"}')
|
|
384
|
+
params.append(filter_svmsg_sdate)
|
|
385
|
+
if filter_svmsg_edate and filter_svmsg_edate != 'None':
|
|
386
|
+
where.append(f'svmsg_date<={"%s" if pg_enabled else "?"}')
|
|
387
|
+
params.append(filter_svmsg_edate)
|
|
388
|
+
sql += ' WHERE ' + ' AND '.join(where) if len(where)>0 else ''
|
|
389
|
+
if groupby and len(groupby) > 0:
|
|
390
|
+
sql += ' GROUP BY ' + ', '.join([f"{_date_format(pg_enabled, g, groupby_date_format)}" for g in groupby])
|
|
391
|
+
if sort and len(sort) > 0:
|
|
392
|
+
sql += ' ORDER BY ' + ', '.join([f"{k} {v}" for k, v in sort.items()])
|
|
393
|
+
else:
|
|
394
|
+
sql += ' ORDER BY svmsg_date DESC'
|
|
395
|
+
if offset > 0:
|
|
396
|
+
sql += f' OFFSET {"%s" if pg_enabled else "?"}'
|
|
397
|
+
params.append(offset)
|
|
398
|
+
if limit > 0:
|
|
399
|
+
sql += f' LIMIT {"%s" if pg_enabled else "?"}'
|
|
400
|
+
params.append(limit)
|
|
401
|
+
cursor.execute(sql, tuple(params))
|
|
402
|
+
rows = cursor.fetchall()
|
|
403
|
+
if not rows:
|
|
404
|
+
rescode, msg = (self.RESP_WARN, dict(warn="No data found"))
|
|
405
|
+
redis_cli.rpush(reskey, msg)
|
|
406
|
+
return rescode
|
|
407
|
+
else:
|
|
408
|
+
rescode, msg = (self.RESP_SCCESS, dict(success=rows))
|
|
409
|
+
redis_cli.rpush(reskey, msg)
|
|
410
|
+
return rescode
|
|
411
|
+
finally:
|
|
412
|
+
cursor.close()
|
|
413
|
+
except Exception as e:
|
|
414
|
+
logger.warning(f"Failed to write: {e}", exc_info=True)
|
|
415
|
+
redis_cli.rpush(reskey, dict(warn=f"Failed to write: {e}"))
|
|
416
|
+
return self.RESP_WARN
|