Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- """
- Retrieves history data for a given numeric (either int or float) item_id
- """
- from grafana_api.grafana_face import GrafanaFace
- from pyzabbix import ZabbixAPI
- from datetime import datetime
- from decimal import *
- import time
- import sys
- import requests
- # The hostname at which the Zabbix web interface is available
- ZABBIX_SERVER = 'https://zbx.orionnet.ru'
- zapi = ZabbixAPI(ZABBIX_SERVER)
- # Login to the Zabbix API
- zapi.login('api', 'fd75fc1cd6ca7b87b234125fb78b407ca5f079c6e670af9ff4d8cde32b58eccb')
- host_id_list = zapi.host.get(
- output='hostid',
- filter={ 'host': sys.argv[1] }
- )
- host_id=host_id_list[0].get("hostid",-1)
- print(host_id)
- host_name_ = zapi.host.get(
- output=['name'],
- filter={ 'host': sys.argv[1] }
- )
- host_name=host_name_[0].get("name",-1)
- print(host_name)
- url='https://api:fd75fc1cd6ca7b87b234125fb78b407ca5f079c6e670af9ff4d8cde32b58eccb@netstat.orionnet.ru/api/dashboards/db'
- data='''{
- "dashboard": {
- "id": null,
- "uid": null,
- "title": "test dashboard",
- "tags": ["тест", "tag1", "tag2", "tagN"],
- "timezone": "browser",
- "schemaVersion": null,
- "version": 0,
- "panels": [{
- "collapsed": true,
- "gridPos": {
- "h": 1,
- "w": 24,
- "x": 0,
- "y": 0
- },
- "id": null,
- "panels": [
- {
- "aliasColors": {},
- "bars": false,
- "dashLength": 10,
- "dashes": false,
- "datasource": "zabbix api",
- "fill": 1,
- "gridPos": {
- "h": 9,
- "w": 12,
- "x": 0,
- "y": 1
- },
- "id": null,
- "legend": {
- "avg": false,
- "current": false,
- "max": false,
- "min": false,
- "show": true,
- "total": false,
- "values": false
- },
- "lines": true,
- "linewidth": 1,
- "nullPointMode": "null",
- "percentage": false,
- "pointradius": 5,
- "points": false,
- "renderer": "flot",
- "seriesOverrides": [],
- "spaceLength": 10,
- "stack": false,
- "steppedLine": false,
- "targets": [{
- "application": {
- "filter": "General info"
- },
- "functions": [],
- "group": {
- "filter": "C32"
- },
- "host": {
- "filter": "Красноярск: Партизана Железняка 32 C32"
- },
- "item": {
- "filter": "CPU utilization 5 sec"
- },
- "mode": 0,
- "options": {
- "showDisabledItems": false,
- "skipEmptyValues": false
- },
- "refId": "A",
- "resultFormat": "time_series",
- "table": {
- "skipEmptyValues": false
- },
- "triggers": {
- "acknowledged": 2,
- "count": true,
- "minSeverity": 3
- }
- }],
- "thresholds": [],
- "timeFrom": null,
- "timeShift": null,
- "title": "C32 CPU 5s",
- "tooltip": {
- "shared": true,
- "sort": 0,
- "value_type": "individual"
- },
- "type": "graph",
- "xaxis": {
- "buckets": null,
- "mode": "time",
- "name": null,
- "show": true,
- "values": []
- },
- "yaxes": [{
- "format": "percent",
- "label": null,
- "logBase": 1,
- "max": null,
- "min": null,
- "show": true
- },
- {
- "format": "short",
- "label": null,
- "logBase": 1,
- "max": null,
- "min": null,
- "show": true
- }
- ],
- "yaxis": {
- "align": false,
- "alignLevel": null
- }
- },
- {
- "aliasColors": {},
- "bars": false,
- "dashLength": 10,
- "dashes": false,
- "datasource": "zabbix api",
- "fill": 1,
- "gridPos": {
- "h": 9,
- "w": 12,
- "x": 12,
- "y": 1
- },
- "id": 5,
- "legend": {
- "avg": false,
- "current": false,
- "max": false,
- "min": false,
- "show": true,
- "total": false,
- "values": false
- },
- "lines": true,
- "linewidth": 1,
- "links": [],
- "nullPointMode": "null",
- "percentage": false,
- "pointradius": 5,
- "points": false,
- "renderer": "flot",
- "seriesOverrides": [],
- "spaceLength": 10,
- "stack": false,
- "steppedLine": false,
- "targets": [{
- "application": {
- "filter": "General info"
- },
- "functions": [],
- "group": {
- "filter": "C32"
- },
- "host": {
- "filter": "Красноярск: Партизана Железняка 32 C32"
- },
- "item": {
- "filter": "CPU utilization 1 min"
- },
- "mode": 0,
- "options": {
- "showDisabledItems": false,
- "skipEmptyValues": false
- },
- "refId": "A",
- "resultFormat": "time_series",
- "table": {
- "skipEmptyValues": false
- },
- "triggers": {
- "acknowledged": 2,
- "count": true,
- "minSeverity": 3
- }
- }],
- "thresholds": [],
- "timeFrom": null,
- "timeShift": null,
- "title": "C32 CPU 1m",
- "tooltip": {
- "shared": true,
- "sort": 0,
- "value_type": "individual"
- },
- "type": "graph",
- "xaxis": {
- "buckets": null,
- "mode": "time",
- "name": null,
- "show": true,
- "values": []
- },
- "yaxes": [{
- "format": "percent",
- "label": null,
- "logBase": 1,
- "max": null,
- "min": null,
- "show": true
- },
- {
- "format": "short",
- "label": null,
- "logBase": 1,
- "max": null,
- "min": null,
- "show": true
- }
- ],
- "yaxis": {
- "align": false,
- "alignLevel": null
- }
- }
- ],
- "title": "Status",
- "type": "row"
- },
- {
- "collapsed": true,
- "gridPos": {
- "h": 1,
- "w": 24,
- "x": 0,
- "y": 1
- },
- "id": null,
- "panels": [],
- "title": "test Row title 2",
- "type": "row"
- },
- {
- "collapsed": true,
- "gridPos": {
- "h": 1,
- "w": 24,
- "x": 0,
- "y": 1
- },
- "id": null,
- "panels": [],
- "title": "test Row title 3",
- "type": "row"
- }
- ]
- },
- "folderId": 90,
- "overwrite": true
- }'''.encode("utf-8")
- headers={"Content-Type": 'application/json'}
- response = requests.post(url, data=data,headers=headers)
- print (response.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement