mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-05-06 23:26:50 +00:00
* perf: change i18n
* perf: pam
* perf: change translate
* perf: add check account
* perf: add date field
* perf: add account filter
* perf: remove some js
* perf: add account status action
* perf: update pam
* perf: 修改 discover account
* perf: update filter
* perf: update gathered account
* perf: 修改账号同步
* perf: squash migrations
* perf: update pam
* perf: change i18n
* perf: update account risk
* perf: 更新风险发现
* perf: remove css
* perf: Admin connection token
* perf: Add a switch to check connectivity after changing the password, and add a custom ssh command for push tasks
* perf: Modify account migration files
* perf: update pam
* perf: remove to check account dir
* perf: Admin connection token
* perf: update check account
* perf: 优化发送结果
* perf: update pam
* perf: update bulk update create
* perf: prepaire using thread timer for bulk_create_decorator
* perf: update bulk create decorator
* perf: 优化 playbook manager
* perf: 优化收集账号的报表
* perf: Update poetry
* perf: Update Dockerfile with new base image tag
* fix: Account migrate 0012 file
* perf: 修改备份
* perf: update pam
* fix: Expand resource_type filter to include raw type
* feat: PAM Service (#14552)
* feat: PAM Service
* perf: import package name
---------
Co-authored-by: jiangweidong <1053570670@qq.com>
* perf: Change secret dashboard (#14551)
Co-authored-by: feng <1304903146@qq.com>
* perf: update migrations
* perf: 修改支持 pam
* perf: Change secret record table dashboard
* perf: update status
* fix: Automation send report
* perf: Change secret report
* feat: windows accounts gather
* perf: update change status
* perf: Account backup
* perf: Account backup report
* perf: Account migrate
* perf: update service to application
* perf: update migrations
* perf: update logo
* feat: oracle accounts gather (#14571)
* feat: oracle accounts gather
* feat: sqlserver accounts gather
* feat: postgresql accounts gather
* feat: mysql accounts gather
---------
Co-authored-by: wangruidong <940853815@qq.com>
* feat: mongodb accounts gather
* perf: Change secret
* perf: Migrate
* perf: Merge conflicting migration files
* perf: Change secret
* perf: Automation filter org
* perf: Account push
* perf: Random secret string
* perf: Enhance SQL query and update risk handling in accounts
* perf: Ticket filter assignee_id
* perf: 修改 account remote
* perf: 修改一些 adhoc 任务
* perf: Change secret
* perf: Remove push account extra api
* perf: update status
* perf: The entire organization can view activity log
* fix: risk field check
* perf: add account details api
* perf: add demo mode
* perf: Delete gather_account
* perf: Perfect solution to account version problem
* perf: Update status action to handle multiple accounts
* perf: Add GatherAccountDetailField and update serializers
* perf: Display account history in combination with password change records
* perf: Lina translate
* fix: Update mysql_filter to handle nested user info
* perf: Admin connection token validate_permission account
* perf: copy move account
* perf: account filter risk
* perf: account risk filter
* perf: Copy move account failed message
* fix: gather account sync account to asset
* perf: Pam dashboard
* perf: Account dashboard total accounts
* perf: Pam dashboard
* perf: Change secret filter account secret_reset
* perf: 修改 risk filter
* perf: pam translate
* feat: Check for leaked duplicate passwords. (#14711)
* feat: Check for leaked duplicate passwords.
* perf: Use SQLite instead of txt as leak password database
---------
Co-authored-by: jiangweidong <1053570670@qq.com>
Co-authored-by: 老广 <ibuler@qq.com>
* perf: merge with remote
* perf: Add risk change_password_add handle
* perf: Pam dashboard
* perf: check account manager import
* perf: 重构扫描
* perf: 修改 db
* perf: Gather account manager
* perf: update change db lib
* perf: dashboard
* perf: Account gather
* perf: 修改 asset get queryset
* perf: automation report
* perf: Pam account
* perf: Pam dashboard api
* perf: risk add account
* perf: 修改 risk check
* perf: Risk account
* perf: update risk add reopen action
* perf: add pylintrc
* Revert "perf: automation report"
This reverts commit 22aee54207
.
* perf: check account engine
* perf: Perf: Optimism Gather Report Style
* Perf: Remove unuser actions
* Perf: Perf push account
* perf: perf gather account
* perf: Automation report
* perf: Push account recorder
* perf: Push account record
* perf: Pam dashboard
* perf: perf
* perf: update intergration
* perf: integrations application detail add account tab page
* feat: Custom change password supports configuration of interactive items
* perf: Go and Python demo code
* perf: Custom secret change
* perf: add user filter
* perf: translate
* perf: Add demo code docs
* perf: update some i18n
* perf: update some i18n
* perf: Add Java, Node, Go, and cURL demo code
* perf: Translate
* perf: Change secret translate
* perf: Translate
* perf: update some i18n
* perf: translate
* perf: Ansible playbook
* perf: update some choice
* perf: update some choice
* perf: update account serializer remote unused code
* perf: conflict
* perf: update import
---------
Co-authored-by: ibuler <ibuler@qq.com>
Co-authored-by: feng <1304903146@qq.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: wangruidong <940853815@qq.com>
Co-authored-by: jiangweidong <1053570670@qq.com>
Co-authored-by: feng626 <57284900+feng626@users.noreply.github.com>
Co-authored-by: zhaojisen <1301338853@qq.com>
284 lines
8.8 KiB
Python
284 lines
8.8 KiB
Python
#!/usr/bin/python
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
DOCUMENTATION = r'''
|
|
---
|
|
module: oracle_info
|
|
short_description: Gather information about Oracle servers
|
|
description:
|
|
- Gathers information about Oracle servers.
|
|
|
|
options:
|
|
filter:
|
|
description:
|
|
- Limit the collected information by comma separated string or YAML list.
|
|
- Allowable values are C(version), C(databases), C(settings), C(users).
|
|
- By default, collects all subsets.
|
|
- You can use '!' before value (for example, C(!users)) to exclude it from the information.
|
|
- If you pass including and excluding values to the filter, for example, I(filter=!settings,version),
|
|
the excluding values, C(!settings) in this case, will be ignored.
|
|
type: list
|
|
elements: str
|
|
login_db:
|
|
description:
|
|
- Database name to connect to.
|
|
- It makes sense if I(login_user) is allowed to connect to a specific database only.
|
|
type: str
|
|
exclude_fields:
|
|
description:
|
|
- List of fields which are not needed to collect.
|
|
- "Supports elements: C(db_size). Unsupported elements will be ignored."
|
|
type: list
|
|
elements: str
|
|
'''
|
|
|
|
EXAMPLES = r'''
|
|
- name: Get Oracle version with non-default credentials
|
|
oracle_info:
|
|
login_user: mysuperuser
|
|
login_password: mysuperpass
|
|
login_database: service_name
|
|
filter: version
|
|
|
|
- name: Collect all info except settings and users by sys
|
|
oracle_info:
|
|
login_user: sys
|
|
login_password: sys_pass
|
|
login_database: service_name
|
|
filter: "!settings,!users"
|
|
exclude_fields: db_size
|
|
'''
|
|
|
|
RETURN = r'''
|
|
version:
|
|
description: Database server version.
|
|
returned: if not excluded by filter
|
|
type: dict
|
|
sample: { "version": {"full": "11.2.0.1.0"} }
|
|
contains:
|
|
full:
|
|
description: Full server version.
|
|
returned: if not excluded by filter
|
|
type: str
|
|
sample: "11.2.0.1.0"
|
|
databases:
|
|
description: Information about databases.
|
|
returned: if not excluded by filter
|
|
type: dict
|
|
sample:
|
|
- { "USERS": { "size": 5242880 }, "EXAMPLE": { "size": 104857600 } }
|
|
contains:
|
|
size:
|
|
description: Database size in bytes.
|
|
returned: if not excluded by filter
|
|
type: dict
|
|
sample: { 'size': 656594 }
|
|
settings:
|
|
description: Global settings (variables) information.
|
|
returned: if not excluded by filter
|
|
type: dict
|
|
sample:
|
|
- { "result_cache_mode": "MANUAL", "instance_type": "RDBMS" }
|
|
users:
|
|
description: Users information.
|
|
returned: if not excluded by filter
|
|
type: dict
|
|
sample:
|
|
- { "USERS": { "TEST": { "USERNAME": "TEST", "ACCOUNT_STATUS": "OPEN" } } }
|
|
'''
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from libs.ansible.modules_utils.oracle_common import (
|
|
OracleClient, oracle_common_argument_spec
|
|
)
|
|
|
|
|
|
class OracleInfo(object):
|
|
def __init__(self, module, oracle_client):
|
|
self.module = module
|
|
self.oracle_client = oracle_client
|
|
self.info = {
|
|
'version': {}, 'databases': {},
|
|
'settings': {}, 'users': {},
|
|
}
|
|
|
|
def get_info(self, filter_, exclude_fields):
|
|
include_list = []
|
|
exclude_list = []
|
|
|
|
if filter_:
|
|
partial_info = {}
|
|
|
|
for fi in filter_:
|
|
if fi.lstrip('!') not in self.info:
|
|
self.module.warn('filter element: %s is not allowable, ignored' % fi)
|
|
continue
|
|
|
|
if fi[0] == '!':
|
|
exclude_list.append(fi.lstrip('!'))
|
|
else:
|
|
include_list.append(fi)
|
|
|
|
if include_list:
|
|
self.__collect(exclude_fields, set(include_list))
|
|
|
|
for i in self.info:
|
|
if i in include_list:
|
|
partial_info[i] = self.info[i]
|
|
else:
|
|
not_in_exclude_list = list(set(self.info) - set(exclude_list))
|
|
self.__collect(exclude_fields, set(not_in_exclude_list))
|
|
|
|
for i in self.info:
|
|
if i not in exclude_list:
|
|
partial_info[i] = self.info[i]
|
|
return partial_info
|
|
else:
|
|
self.__collect(exclude_fields, set(self.info))
|
|
return self.info
|
|
|
|
def __collect(self, exclude_fields, wanted):
|
|
"""Collect all possible subsets."""
|
|
if 'version' in wanted:
|
|
self.__get_version()
|
|
|
|
if 'settings' in wanted:
|
|
self.__get_settings()
|
|
|
|
if 'databases' in wanted:
|
|
self.__get_databases(exclude_fields)
|
|
#
|
|
if 'users' in wanted:
|
|
self.__get_users()
|
|
|
|
def __get_version(self):
|
|
version_sql = 'SELECT VERSION FROM PRODUCT_COMPONENT_VERSION where ROWNUM=1'
|
|
rtn, err = self.oracle_client.execute(version_sql, exception_to_fail=True)
|
|
self.info['version'] = {'full': rtn.get('version')}
|
|
|
|
def __get_settings(self):
|
|
"""Get global variables (instance settings)."""
|
|
|
|
def _set_settings_value(item_dict):
|
|
try:
|
|
self.info['settings'][item_dict['name']] = item_dict['value']
|
|
except KeyError:
|
|
pass
|
|
|
|
settings_sql = "SELECT name, value FROM V$PARAMETER"
|
|
rtn, err = self.oracle_client.execute(settings_sql, exception_to_fail=True)
|
|
|
|
if isinstance(rtn, dict):
|
|
_set_settings_value(rtn)
|
|
elif isinstance(rtn, list):
|
|
for i in rtn:
|
|
_set_settings_value(i)
|
|
|
|
def __get_users(self):
|
|
"""Get user info."""
|
|
|
|
def _set_users_roles(username, item_dict):
|
|
users_sql = f"SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = '{username}';"
|
|
try:
|
|
rtn, err = self.oracle_client.execute(users_sql, exception_to_fail=True)
|
|
item_dict['roles'] = [r['role'] for r in rtn]
|
|
except Exception:
|
|
pass
|
|
|
|
def _set_users_privileges(username, item_dict):
|
|
users_sql = f"SELECT PRIVILEGE FROM DBA_SYS_PRIVS WHERE GRANTEE = '{username}';"
|
|
try:
|
|
rtn, err = self.oracle_client.execute(users_sql, exception_to_fail=True)
|
|
item_dict['privileges'] = [r['privilege'] for r in rtn]
|
|
except Exception:
|
|
pass
|
|
|
|
def _set_users_value(item_dict):
|
|
try:
|
|
tablespace = item_dict.pop('default_tablespace')
|
|
username = item_dict.pop('username')
|
|
partial_users = self.info['users'].get(tablespace, {})
|
|
_set_users_roles(username, item_dict)
|
|
_set_users_privileges(username, item_dict)
|
|
partial_users[username] = item_dict
|
|
self.info['users'][tablespace] = partial_users
|
|
except KeyError:
|
|
pass
|
|
|
|
users_sql = "SELECT * FROM dba_users"
|
|
rtn, err = self.oracle_client.execute(users_sql, exception_to_fail=True)
|
|
if isinstance(rtn, dict):
|
|
_set_users_value(rtn)
|
|
elif isinstance(rtn, list):
|
|
for i in rtn:
|
|
_set_users_value(i)
|
|
|
|
def __get_databases(self, exclude_fields):
|
|
"""Get info about databases."""
|
|
|
|
def _set_databases_value(item_dict):
|
|
try:
|
|
tablespace_name = item_dict.pop('tablespace_name')
|
|
size = item_dict.get('size')
|
|
partial_params = {}
|
|
if size:
|
|
partial_params['size'] = size
|
|
self.info['databases'][tablespace_name] = partial_params
|
|
except KeyError:
|
|
pass
|
|
|
|
database_sql = 'SELECT ' \
|
|
' tablespace_name, sum(bytes) as "size"' \
|
|
'FROM dba_data_files GROUP BY tablespace_name'
|
|
if exclude_fields and 'db_size' in exclude_fields:
|
|
database_sql = "SELECT " \
|
|
" tablespace_name " \
|
|
"FROM dba_data_files GROUP BY tablespace_name"
|
|
|
|
rtn, err = self.oracle_client.execute(database_sql, exception_to_fail=True)
|
|
if isinstance(rtn, dict):
|
|
_set_databases_value(rtn)
|
|
elif isinstance(rtn, list):
|
|
for i in rtn:
|
|
_set_databases_value(i)
|
|
|
|
|
|
# ===========================================
|
|
# Module execution.
|
|
#
|
|
|
|
|
|
def main():
|
|
argument_spec = oracle_common_argument_spec()
|
|
argument_spec.update(
|
|
filter=dict(type='list'),
|
|
exclude_fields=dict(type='list'),
|
|
)
|
|
|
|
module = AnsibleModule(
|
|
argument_spec=argument_spec,
|
|
supports_check_mode=True,
|
|
)
|
|
|
|
filter_ = module.params['filter']
|
|
exclude_fields = module.params['exclude_fields']
|
|
|
|
if filter_:
|
|
filter_ = [f.strip() for f in filter_]
|
|
|
|
if exclude_fields:
|
|
exclude_fields = set([f.strip() for f in exclude_fields])
|
|
|
|
oracle_client = OracleClient(module)
|
|
oracle = OracleInfo(module, oracle_client)
|
|
|
|
module.exit_json(changed=False, **oracle.get_info(filter_, exclude_fields))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|