fix: discover scripts (#458)

Co-authored-by: wang-liang0615 <dhuwl0615@163.com>
This commit is contained in:
ivonGwy 2024-03-29 15:48:46 +08:00 committed by GitHub
parent d08827d086
commit 4232094aed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 74 additions and 73 deletions

View File

@ -419,10 +419,10 @@ const cmdb_en = {
updateFields: 'Update Field', updateFields: 'Update Field',
pluginScript: `# -*- coding:utf-8 -*- pluginScript: `# -*- coding:utf-8 -*-
import json import json
class AutoDiscovery(object): class AutoDiscovery(object):
@property @property
def unique_key(self): def unique_key(self):
@ -458,7 +458,7 @@ const cmdb_en = {
return [] return []
if __name__ == "__main__": if __name__ == "__main__":
result = AutoDiscovery().run() result = AutoDiscovery().run()
if isinstance(result, list): if isinstance(result, list):
print("AutoDiscovery::Result::{}".format(json.dumps(result))) print("AutoDiscovery::Result::{}".format(json.dumps(result)))

View File

@ -419,29 +419,29 @@ const cmdb_zh = {
updateFields: '更新字段', updateFields: '更新字段',
pluginScript: `# -*- coding:utf-8 -*- pluginScript: `# -*- coding:utf-8 -*-
import json import json
class AutoDiscovery(object): class AutoDiscovery(object):
@property @property
def unique_key(self): def unique_key(self):
""" """
:return: 返回唯一属性的名字 :return: Returns the name of a unique attribute
""" """
return return
@staticmethod @staticmethod
def attributes(): def attributes():
""" """
定义属性字段 Define attribute fields
:return: 返回属性字段列表, 列表项是(名称, 类型, 描述), 名称必须是英文 :return: Returns a list of attribute fields. The list items are (name, type, description). The name must be in English.
类型: String Integer Float Date DateTime Time JSON type: String Integer Float Date DateTime Time JSON
例如: For example:
return [ return [
("ci_type", "String", "模型名称"), ("ci_type", "String", "CIType name"),
("private_ip", "String", "内网IP, 多值逗号分隔") ("private_ip", "String", "Internal IP, multiple values separated by commas")
] ]
""" """
return [] return []
@ -449,20 +449,21 @@ const cmdb_zh = {
@staticmethod @staticmethod
def run(): def run():
""" """
执行入口, 返回采集的属性值 Execution entry, returns collected attribute values
:return: 返回一个列表, 列表项是字典, 字典key是属性名称, value是属性值 :return:
例如: Returns a list, the list item is a dictionary, the dictionary key is the attribute name, and the value is the attribute value
For example:
return [dict(ci_type="server", private_ip="192.168.1.1")] return [dict(ci_type="server", private_ip="192.168.1.1")]
""" """
return [] return []
if __name__ == "__main__": if __name__ == "__main__":
result = AutoDiscovery().run() result = AutoDiscovery().run()
if isinstance(result, list): if isinstance(result, list):
print("AutoDiscovery::Result::{}".format(json.dumps(result))) print("AutoDiscovery::Result::{}".format(json.dumps(result)))
else: else:
print("ERROR: 采集返回必须是列表") print("ERROR: The collection return must be a list")
`, `,
server: '物理机', server: '物理机',
vserver: '虚拟机', vserver: '虚拟机',