Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. """
  4. Retrieves history data for a given numeric (either int or float) item_id
  5. """
  6. from grafana_api.grafana_face import GrafanaFace
  7. from pyzabbix import ZabbixAPI
  8. from datetime import datetime
  9. from decimal import *
  10. import time
  11. import sys
  12. import requests
  13. # The hostname at which the Zabbix web interface is available
  14. ZABBIX_SERVER = 'https://zbx.orionnet.ru'
  15.  
  16. zapi = ZabbixAPI(ZABBIX_SERVER)
  17.  
  18. # Login to the Zabbix API
  19. zapi.login('api', 'fd75fc1cd6ca7b87b234125fb78b407ca5f079c6e670af9ff4d8cde32b58eccb')
  20. host_id_list = zapi.host.get(
  21. output='hostid',
  22. filter={ 'host': sys.argv[1] }
  23. )
  24. host_id=host_id_list[0].get("hostid",-1)
  25. print(host_id)
  26.  
  27. host_name_ = zapi.host.get(
  28. output=['name'],
  29. filter={ 'host': sys.argv[1] }
  30. )
  31. host_name=host_name_[0].get("name",-1)
  32. print(host_name)
  33.  
  34. url='https://api:fd75fc1cd6ca7b87b234125fb78b407ca5f079c6e670af9ff4d8cde32b58eccb@netstat.orionnet.ru/api/dashboards/db'
  35. data='''{
  36. "dashboard": {
  37. "id": null,
  38. "uid": null,
  39. "title": "test dashboard",
  40. "tags": ["тест", "tag1", "tag2", "tagN"],
  41. "timezone": "browser",
  42. "schemaVersion": null,
  43. "version": 0,
  44. "panels": [{
  45. "collapsed": true,
  46. "gridPos": {
  47. "h": 1,
  48. "w": 24,
  49. "x": 0,
  50. "y": 0
  51. },
  52. "id": null,
  53. "panels": [
  54. {
  55. "aliasColors": {},
  56. "bars": false,
  57. "dashLength": 10,
  58. "dashes": false,
  59. "datasource": "zabbix api",
  60. "fill": 1,
  61. "gridPos": {
  62. "h": 9,
  63. "w": 12,
  64. "x": 0,
  65. "y": 1
  66. },
  67. "id": null,
  68. "legend": {
  69. "avg": false,
  70. "current": false,
  71. "max": false,
  72. "min": false,
  73. "show": true,
  74. "total": false,
  75. "values": false
  76. },
  77. "lines": true,
  78. "linewidth": 1,
  79. "nullPointMode": "null",
  80. "percentage": false,
  81. "pointradius": 5,
  82. "points": false,
  83. "renderer": "flot",
  84. "seriesOverrides": [],
  85. "spaceLength": 10,
  86. "stack": false,
  87. "steppedLine": false,
  88. "targets": [{
  89. "application": {
  90. "filter": "General info"
  91. },
  92. "functions": [],
  93. "group": {
  94. "filter": "C32"
  95. },
  96. "host": {
  97. "filter": "Красноярск: Партизана Железняка 32 C32"
  98. },
  99. "item": {
  100. "filter": "CPU utilization 5 sec"
  101. },
  102. "mode": 0,
  103. "options": {
  104. "showDisabledItems": false,
  105. "skipEmptyValues": false
  106. },
  107. "refId": "A",
  108. "resultFormat": "time_series",
  109. "table": {
  110. "skipEmptyValues": false
  111. },
  112. "triggers": {
  113. "acknowledged": 2,
  114. "count": true,
  115. "minSeverity": 3
  116. }
  117. }],
  118. "thresholds": [],
  119. "timeFrom": null,
  120. "timeShift": null,
  121. "title": "C32 CPU 5s",
  122. "tooltip": {
  123. "shared": true,
  124. "sort": 0,
  125. "value_type": "individual"
  126. },
  127. "type": "graph",
  128. "xaxis": {
  129. "buckets": null,
  130. "mode": "time",
  131. "name": null,
  132. "show": true,
  133. "values": []
  134. },
  135. "yaxes": [{
  136. "format": "percent",
  137. "label": null,
  138. "logBase": 1,
  139. "max": null,
  140. "min": null,
  141. "show": true
  142. },
  143. {
  144. "format": "short",
  145. "label": null,
  146. "logBase": 1,
  147. "max": null,
  148. "min": null,
  149. "show": true
  150. }
  151. ],
  152. "yaxis": {
  153. "align": false,
  154. "alignLevel": null
  155. }
  156. },
  157. {
  158. "aliasColors": {},
  159. "bars": false,
  160. "dashLength": 10,
  161. "dashes": false,
  162. "datasource": "zabbix api",
  163. "fill": 1,
  164. "gridPos": {
  165. "h": 9,
  166. "w": 12,
  167. "x": 12,
  168. "y": 1
  169. },
  170. "id": 5,
  171. "legend": {
  172. "avg": false,
  173. "current": false,
  174. "max": false,
  175. "min": false,
  176. "show": true,
  177. "total": false,
  178. "values": false
  179. },
  180. "lines": true,
  181. "linewidth": 1,
  182. "links": [],
  183. "nullPointMode": "null",
  184. "percentage": false,
  185. "pointradius": 5,
  186. "points": false,
  187. "renderer": "flot",
  188. "seriesOverrides": [],
  189. "spaceLength": 10,
  190. "stack": false,
  191. "steppedLine": false,
  192. "targets": [{
  193. "application": {
  194. "filter": "General info"
  195. },
  196. "functions": [],
  197. "group": {
  198. "filter": "C32"
  199. },
  200. "host": {
  201. "filter": "Красноярск: Партизана Железняка 32 C32"
  202. },
  203. "item": {
  204. "filter": "CPU utilization 1 min"
  205. },
  206. "mode": 0,
  207. "options": {
  208. "showDisabledItems": false,
  209. "skipEmptyValues": false
  210. },
  211. "refId": "A",
  212. "resultFormat": "time_series",
  213. "table": {
  214. "skipEmptyValues": false
  215. },
  216. "triggers": {
  217. "acknowledged": 2,
  218. "count": true,
  219. "minSeverity": 3
  220. }
  221. }],
  222. "thresholds": [],
  223. "timeFrom": null,
  224. "timeShift": null,
  225. "title": "C32 CPU 1m",
  226. "tooltip": {
  227. "shared": true,
  228. "sort": 0,
  229. "value_type": "individual"
  230. },
  231. "type": "graph",
  232. "xaxis": {
  233. "buckets": null,
  234. "mode": "time",
  235. "name": null,
  236. "show": true,
  237. "values": []
  238. },
  239. "yaxes": [{
  240. "format": "percent",
  241. "label": null,
  242. "logBase": 1,
  243. "max": null,
  244. "min": null,
  245. "show": true
  246. },
  247. {
  248. "format": "short",
  249. "label": null,
  250. "logBase": 1,
  251. "max": null,
  252. "min": null,
  253. "show": true
  254. }
  255. ],
  256. "yaxis": {
  257. "align": false,
  258. "alignLevel": null
  259. }
  260. }
  261. ],
  262. "title": "Status",
  263. "type": "row"
  264. },
  265. {
  266. "collapsed": true,
  267. "gridPos": {
  268. "h": 1,
  269. "w": 24,
  270. "x": 0,
  271. "y": 1
  272. },
  273. "id": null,
  274. "panels": [],
  275. "title": "test Row title 2",
  276. "type": "row"
  277. },
  278. {
  279. "collapsed": true,
  280. "gridPos": {
  281. "h": 1,
  282. "w": 24,
  283. "x": 0,
  284. "y": 1
  285. },
  286. "id": null,
  287. "panels": [],
  288. "title": "test Row title 3",
  289. "type": "row"
  290. }
  291.  
  292. ]
  293. },
  294. "folderId": 90,
  295. "overwrite": true
  296. }'''.encode("utf-8")
  297. headers={"Content-Type": 'application/json'}
  298. response = requests.post(url, data=data,headers=headers)
  299. print (response.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement