bcm_model.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the
  9. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  10. # either express or implied. See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. """
  13. This module provides a model class for BCM.
  14. """
  15. class CustomDimensionModel(dict):
  16. """
  17. This class define custom dimension.
  18. """
  19. def __init__(self, name, order, alias=""):
  20. """
  21. :param name:
  22. custom dimension name.
  23. :type name: string
  24. :param alias:
  25. custom dimension alias.
  26. :type alias: string
  27. :param order:
  28. custom dimension order.
  29. :type order: int
  30. """
  31. super(CustomDimensionModel, self).__init__()
  32. self["name"] = name
  33. self["order"] = order
  34. self["alias"] = alias
  35. class EventLevel(object):
  36. """
  37. This class define event level.
  38. """
  39. NOTICE = "NOTICE"
  40. WARNING = "WARNING"
  41. MAJOR = "MAJOR"
  42. CRITICAL = "CRITICAL"
  43. __all_members = (NOTICE, WARNING, MAJOR, CRITICAL)
  44. @classmethod
  45. def contains(cls, event_level):
  46. """
  47. whether event_level is valid
  48. :param event_level:
  49. event level
  50. :type event_level: string
  51. :return:
  52. :rtype true/false
  53. """
  54. if event_level in cls.__all_members:
  55. return True
  56. return False
  57. @classmethod
  58. def all_event_levels(cls):
  59. """
  60. get all event levels
  61. :return:
  62. :rtype tuple
  63. """
  64. return cls.__all_members
  65. class DisableTime(dict):
  66. """
  67. This class define disable time
  68. """
  69. def __init__(self, from_time, to_time):
  70. """
  71. :param from_time: disable start time, such as 08:00:00
  72. :type from_time: string
  73. :param to_time: disable end time, such as 08:00:00
  74. :type to_time: string
  75. """
  76. super(DisableTime, self).__init__()
  77. self["from"] = from_time
  78. self["to"] = to_time
  79. class Notification(dict):
  80. """
  81. This class define notification
  82. """
  83. def __init__(self, type, receiver=""):
  84. """
  85. :param type: enum, EMAIL, SMS, PHONE
  86. :type type: string
  87. :param receiver: receiver id
  88. :type receiver string
  89. """
  90. super(Notification, self).__init__()
  91. self["type"] = type
  92. self["receiver"] = receiver
  93. class Member(dict):
  94. """
  95. This class define member
  96. """
  97. def __init__(self, type, id, name):
  98. """
  99. :param type: enum, notifyParty or notifyGroup
  100. :type type: string
  101. :param id: receiver id
  102. :type id string
  103. :param name: receiver's name
  104. :type name: string
  105. """
  106. super(Member, self).__init__()
  107. self["type"] = type
  108. self["id"] = id
  109. self["name"] = name
  110. class ApplicationAlarmRule(dict):
  111. """
  112. This class define application alarm policy config
  113. """
  114. def __init__(self, metric, metric_alias, cycle, statistics, threshold, comparison_operator, count,
  115. sequence, metric_dimensions):
  116. """
  117. :param metric: metric identifier
  118. :type metric: string
  119. :param metric_alias: metric name
  120. :type metric_alias: string
  121. :param cycle: period, second
  122. :type cycle: int
  123. :param statistics: statistics, enum: average, minimum, maximum, sum
  124. :type statistics: string
  125. :param threshold:
  126. :type threshold: float
  127. :param comparison_operator: operator, enum: ">", "<", ">=", "<="
  128. :type: string
  129. :param count:
  130. :type count: int
  131. :param sequence: rule's sequence, begin with 0
  132. :type sequence: int
  133. :param metric_dimensions: dimensions
  134. :type metric_dimensions: list
  135. """
  136. super(ApplicationAlarmRule, self).__init__()
  137. self["metric"] = metric
  138. self["metricAlias"] = metric_alias
  139. self["cycle"] = cycle
  140. self["statistics"] = statistics
  141. self["threshold"] = threshold
  142. self["function"] = "THRESHOLD"
  143. self["comparisonOperator"] = comparison_operator
  144. self["count"] = count
  145. self["sequence"] = sequence
  146. self["metricDimensions"] = metric_dimensions
  147. class ApplicationObjectView(dict):
  148. """
  149. This class define the monitorObjectView in application monitor alarm
  150. """
  151. def __init__(self, monitor_object_name, monitor_object_name_view="", metric_dimension_view=""):
  152. """
  153. :param monitor_object_name: taskName
  154. :type monitor_object_name: string
  155. :param monitor_object_name_view: displayed name
  156. :type monitor_object_name_view: string
  157. :param metric_dimension_view:
  158. :type string
  159. """
  160. super(ApplicationObjectView, self).__init__()
  161. self["monitorObjectName"] = monitor_object_name
  162. self["monitorObjectNameView"] = monitor_object_name_view
  163. self["metricDimensionView"] = metric_dimension_view
  164. class ApplicationMonitorObject(dict):
  165. """
  166. This class define application monitor object
  167. """
  168. def __init__(self, monitor_object_type, monitor_object_view):
  169. """
  170. :param monitor_object_type: enum: APP, SERVICE
  171. :type monitor_object_type: string
  172. :param monitor_object_view: monitor object
  173. :type monitor_object_view: list
  174. """
  175. super(ApplicationMonitorObject, self).__init__()
  176. self["monitorObjectType"] = monitor_object_type
  177. self["monitorObjectView"] = monitor_object_view
  178. class Dimension(dict):
  179. """
  180. This class define dimension.
  181. """
  182. def __init__(self, name, value):
  183. """
  184. :param name: dimension name.
  185. :type name: string
  186. :param value: dimension value.
  187. :type value: string
  188. """
  189. super(Dimension, self).__init__()
  190. self["name"] = name
  191. self["value"] = value
  192. class KV(dict):
  193. """
  194. This class define kv.
  195. """
  196. def __init__(self, key, value):
  197. """
  198. :param key: key.
  199. :type key: string
  200. :param value: dimension value.
  201. :type value: string
  202. """
  203. super(KV, self).__init__()
  204. self["key"] = key
  205. self["value"] = value
  206. class PolicyResource(dict):
  207. """
  208. This class define policy resource.
  209. """
  210. def __init__(self, identifiers, metric_dimensions=None):
  211. """
  212. :param identifiers: identifiers.
  213. :type identifiers: Dimension array
  214. :param metric_dimensions: metric dimensions.
  215. :type metric_dimensions: Dimension array
  216. """
  217. super(PolicyResource, self).__init__()
  218. if metric_dimensions is None:
  219. metric_dimensions = []
  220. self["identifiers"] = identifiers
  221. self["metricDimensions"] = metric_dimensions
  222. class MonitorObject(dict):
  223. """
  224. This class define monitor object.
  225. """
  226. def __init__(self, object_type, names, resources=None, type_name="Instance"):
  227. """
  228. :param object_type: monitor object type.
  229. :type object_type: string
  230. :param names: monitor object names.
  231. :type names: string array
  232. :param resources: monitor object resources.
  233. :type resources: PolicyResource array
  234. :param type_name: monitor object typename.
  235. :type type_name: string
  236. """
  237. super(MonitorObject, self).__init__()
  238. if resources is None:
  239. resources = []
  240. self["type"] = object_type
  241. self["names"] = names
  242. self["resources"] = resources
  243. self["typeName"] = type_name
  244. class AlarmRule(dict):
  245. """
  246. private Long index;
  247. private String metric;
  248. private Long periodInSecond;
  249. private String statistics;
  250. private String threshold;
  251. private String comparisonOperator;
  252. private Integer evaluationPeriodCount;
  253. private List<Dimension> metricDimensions;
  254. This class define alarm rule.
  255. """
  256. def __init__(self, index, metric, period, statistics, threshold, operator, evaluation_count,
  257. metric_dimensions=None):
  258. """
  259. :param index: alarm rule index.
  260. :type index: int
  261. :param metric: metric name.
  262. :type metric: string
  263. :param period: period in second.
  264. :type period: int
  265. :param statistics: statistics.
  266. :type statistics: string
  267. :param threshold: threshold.
  268. :type threshold: string
  269. :param operator: comparison operator.
  270. :type operator: string
  271. :param evaluation_count: evaluation period count.
  272. :type evaluation_count: int
  273. :param metric_dimensions: metric dimensions.
  274. :type metric_dimensions: Dimension array
  275. """
  276. super(AlarmRule, self).__init__()
  277. if metric_dimensions is None:
  278. metric_dimensions = []
  279. self["index"] = index
  280. self["metric"] = metric
  281. self["periodInSecond"] = period
  282. self["statistics"] = statistics
  283. self["threshold"] = threshold
  284. self["comparisonOperator"] = operator
  285. self["evaluationPeriodCount"] = evaluation_count
  286. self["metricDimensions"] = metric_dimensions
  287. class AlarmAction(dict):
  288. """
  289. This class define alarm action.
  290. """
  291. def __init__(self, name, action_id=""):
  292. """
  293. :param name: action name.
  294. :type name: string
  295. :param id: action id.
  296. :type id: string
  297. """
  298. super(AlarmAction, self).__init__()
  299. self["name"] = name
  300. self["id"] = action_id
  301. class AlarmConfigRule(dict):
  302. """
  303. This class define alarm config rule.
  304. """
  305. def __init__(self, metric_name, operator, statistics, threshold, window=60, metric_dimensions=None):
  306. """
  307. :param metric_name: metric name.
  308. :type metric_name: string
  309. :param operator: operator.
  310. :type operator: string
  311. :param statistics: statistics.
  312. :type statistics: string
  313. :param threshold: threshold.
  314. :type threshold: float
  315. :param window: window.
  316. :type window: int
  317. :param metric_dimensions: metric dimensions.
  318. :type metric_dimensions: KV array
  319. """
  320. super(AlarmConfigRule, self).__init__()
  321. if metric_dimensions is None:
  322. metric_dimensions = []
  323. self["metricName"] = metric_name
  324. self["operator"] = operator
  325. self["statistics"] = statistics
  326. self["threshold"] = threshold
  327. self["window"] = window
  328. self["metricDimensions"] = metric_dimensions
  329. class AlarmConfigPolicy(dict):
  330. """
  331. This class define alarm config policy.
  332. """
  333. def __init__(self, rules, alarm_pending_count):
  334. """
  335. :param rules: alarm config rules.
  336. :type rules: AlarmConfigRule array
  337. :param alarm_pending_count: alarm pending period count.
  338. :type alarm_pending_count: int
  339. """
  340. super(AlarmConfigPolicy, self).__init__()
  341. self["rules"] = rules
  342. self["alarmPendingPeriodCount"] = alarm_pending_count
  343. class TargetInstance(dict):
  344. """
  345. This class define alarm config policy target instance.
  346. """
  347. def __init__(self, region, identifiers, metric_dimensions=None):
  348. """
  349. :param region: region.
  350. :type region: string
  351. :param identifiers: identifiers.
  352. :type identifiers: KV array
  353. :param metric_dimensions: metric dimensions.
  354. :type metric_dimensions: KV array
  355. """
  356. super(TargetInstance, self).__init__()
  357. if metric_dimensions is None:
  358. metric_dimensions = []
  359. self["region"] = region
  360. self["identifiers"] = identifiers
  361. self["metricDimensions"] = metric_dimensions
  362. class EventFilter(dict):
  363. """
  364. This class define event filter
  365. """
  366. def __init__(self, event_level, event_type_list, eventAliasNames):
  367. """
  368. :param event_level: event level, enum: NOTICE, WARNING, MAJOR, CRITICAL, * means all
  369. :type event_level: string
  370. :param event_type_list: event type list, * means all
  371. :type event_type_list: list
  372. :param eventAliasNames: event alias name list, * means all
  373. :type eventAliasNames: list
  374. """
  375. super(EventFilter, self).__init__()
  376. self["eventLevel"] = event_level
  377. self["eventTypeList"] = event_type_list
  378. self["eventAliasNames"] = eventAliasNames
  379. class EventResourceFilter(dict):
  380. """
  381. This class define event resource filter
  382. """
  383. def __init__(self, region, type, monitor_object_type, resources):
  384. """
  385. :param region: region
  386. :type region: string
  387. :param type: resource type, enum: APP, SERVICE
  388. :type type: string
  389. :param monitor_object_type: monitor object type, enum: ALL, TAG
  390. :type monitor_object_type: string
  391. :param resources: resource list of EventResource
  392. :type resources: list of EventResource
  393. """
  394. super(EventResourceFilter, self).__init__()
  395. self["region"] = region
  396. self["type"] = type
  397. self["monitorObjectType"] = monitor_object_type
  398. self["resources"] = resources
  399. class EventResource(dict):
  400. """
  401. This class define event resource
  402. """
  403. def __init__(self, identifiers):
  404. """
  405. :param identifiers: resource identifiers
  406. :type identifiers: list of Dimension
  407. """
  408. super(EventResource, self).__init__()
  409. self["identifiers"] = identifiers
  410. class MonitorResource(dict):
  411. """
  412. This class define monitor resource
  413. """
  414. def __init__(self, user_id, region, service_name, type_name, resource_id, identifiers=None,
  415. properties=None, tags=None):
  416. """
  417. :param user_id: user id
  418. :type user_id: string
  419. :param region: region
  420. :type region: string
  421. :param service_name: service name
  422. :type service_name: string
  423. :param type_name: type name
  424. :type type_name: string
  425. :param resource_id: resource id
  426. :type resource_id: string
  427. :param identifiers: identifier list
  428. :type identifiers: list of Dimension
  429. :param properties: property list
  430. :type properties: list of Dimension
  431. :param tags: tag list
  432. :type tags: list of Dimension
  433. """
  434. super(MonitorResource, self).__init__()
  435. self["userId"] = user_id
  436. self["region"] = region
  437. self["serviceName"] = service_name
  438. self["typeName"] = type_name
  439. self["resourceId"] = resource_id
  440. self["identifiers"] = identifiers
  441. self["properties"] = properties
  442. self["tags"] = tags
  443. class MetricDatum(dict):
  444. """
  445. This class metric datum.
  446. """
  447. def __init__(self, metric_name, dimensions, value, timestamp):
  448. """
  449. :param metric_name: metric_name
  450. :type metric_name: string
  451. :param dimensions: dimensions
  452. :type dimensions: list
  453. :param value: value
  454. :type value: double
  455. :param timestamp: timestamp
  456. :type timestamp: string
  457. """
  458. super(MetricDatum, self).__init__()
  459. self["metricName"] = metric_name
  460. self["dimensions"] = dimensions
  461. self["value"] = value
  462. self["timestamp"] = timestamp
  463. class SiteAlarmRule(dict):
  464. """
  465. This class define site alarm policy config
  466. """
  467. def __init__(self, metric, metric_alias, cycle, statistics, threshold, comparison_operator, count,
  468. function, act_on_idcs, act_on_isps, version_site):
  469. """
  470. :param metric: metric identifier
  471. :type metric: string
  472. :param metric_alias: metric name
  473. :type metric_alias: string
  474. :param cycle: period, second
  475. :type cycle: int
  476. :param statistics: statistics, enum: average, minimum, maximum, sum
  477. :type statistics: string
  478. :param threshold:
  479. :type threshold: float
  480. :param comparison_operator: operator, enum: ">", "<", ">=", "<="
  481. :type: string
  482. :param count:
  483. :type count: int
  484. :param function:
  485. :type function: string
  486. :param act_on_idcs:
  487. :type act_on_idcs: list
  488. :param act_on_isps:
  489. :type act_on_isps: list
  490. :param version_site:
  491. :type version_site: string
  492. """
  493. super(SiteAlarmRule, self).__init__()
  494. self["metric"] = metric
  495. self["metricAlias"] = metric_alias
  496. self["cycle"] = cycle
  497. self["statistics"] = statistics
  498. self["threshold"] = threshold
  499. self["function"] = "THRESHOLD"
  500. self["comparisonOperator"] = comparison_operator
  501. self["count"] = count
  502. self["actOnIdcs"] = act_on_idcs
  503. self["actOnIsps"] = act_on_isps
  504. self["versionSite"] = version_site
  505. class CustomAlarmRule(dict):
  506. """
  507. This class define custom alarm policy config
  508. """
  509. def __init__(self, metric, cycle, statistics, threshold, comparison_operator, count,
  510. index, metric_dimensions):
  511. """
  512. :param metric: metric identifier
  513. :type metric: string
  514. :param cycle: period, second
  515. :type cycle: int
  516. :param statistics: statistics, enum: average, minimum, maximum, sum
  517. :type statistics: string
  518. :param threshold:
  519. :type threshold: float
  520. :param comparison_operator: operator, enum: ">", "<", ">=", "<="
  521. :type: string
  522. :param count:
  523. :type count: int
  524. :param index: rule's sequence, begin with 0
  525. :type index: int
  526. :param metric_dimensions: dimensions
  527. :type metric_dimensions: list
  528. """
  529. super(CustomAlarmRule, self).__init__()
  530. self["metricName"] = metric
  531. self["cycle"] = cycle
  532. self["statistics"] = statistics
  533. self["threshold"] = threshold
  534. self["function"] = "THRESHOLD"
  535. self["comparisonOperator"] = comparison_operator
  536. self["count"] = count
  537. self["index"] = index
  538. self["metricDimensions"] = metric_dimensions
  539. class SiteOnceConfig(dict):
  540. """
  541. This class define site once config
  542. """
  543. def __init__(self, anonymous_login=None, method=None, post_content=None, kidnap_white=None, resolve_type=None,
  544. server=None, packet_count=None, port=None, input_type=None, input_data=None, output_type=None,
  545. expected_output=None, username=None, password=None):
  546. """
  547. :param anonymous_login: anonymous login
  548. :type anonymous_login: bool
  549. :param method: method, enum: get, post, put, delete, patch
  550. :type method: string
  551. :param post_content: post content
  552. :type post_content: string
  553. :param kidnap_white: kidnap white
  554. :type kidnap_white: bool
  555. :param resolve_type: resolve type
  556. :type resolve_type: string
  557. :param server: server
  558. :type server: string
  559. :param packet_count: packet count
  560. :type packet_count: int
  561. :param port: port
  562. :type port: int
  563. :param input_type: input type
  564. :type input_type: string
  565. :param input_data: input data
  566. :type input_data: string
  567. :param output_type: output type
  568. :type output_type: string
  569. :param expected_output: expected output
  570. :type expected_output: string
  571. :param username: username
  572. :type username: string
  573. :param password: password
  574. :type password: string
  575. """
  576. super(SiteOnceConfig, self).__init__()
  577. self["anonymousLogin"] = anonymous_login
  578. self["method"] = method
  579. self["postContent"] = post_content
  580. self["kidnapWhite"] = kidnap_white
  581. self["resolveType"] = resolve_type
  582. self["server"] = server
  583. self["packetCount"] = packet_count
  584. self["port"] = port
  585. self["inputType"] = input_type
  586. self["input"] = input_data
  587. self["outputType"] = output_type
  588. self["expectedOutput"] = expected_output
  589. self["username"] = username
  590. self["password"] = password
  591. class AdvancedConfig(dict):
  592. """
  593. This class define advanced site once config
  594. """
  595. def __init__(self, cookies=None, user_agent=None, host=None, response_code=None,
  596. response_check=None, username=None, password=None, input_type=None,
  597. input_data=None, output_type=None, expected_output=None):
  598. """
  599. :param cookies: cookies
  600. :type cookies: string
  601. :param user_agent: user agent
  602. :type user_agent: string
  603. :param host: host
  604. :type host: string
  605. :param response_code: response code
  606. :type response_code: int
  607. :param response_check: response check
  608. :type response_check: bool
  609. :param username: username
  610. :type username: string
  611. :param password: password
  612. :type password: string
  613. :param input_type: input type
  614. :type input_type: string
  615. :param input_data: input data
  616. :type input_data: string
  617. :param output_type: output type
  618. :type output_type: string
  619. :param expected_output: expected output
  620. :type expected_output: string
  621. """
  622. super(AdvancedConfig, self).__init__()
  623. self["cookies"] = cookies
  624. self["userAgent"] = user_agent
  625. self["host"] = host
  626. self["responseCode"] = response_code
  627. self["responseCheck"] = response_check
  628. self["username"] = username
  629. self["password"] = password
  630. self["inputType"] = input_type
  631. self["input"] = input_data
  632. self["outputType"] = output_type
  633. self["expectedOutput"] = expected_output