I am working on OPC DA & AE. For that, I am using the IIOT OPCUA node in Node-red.
With the IIOT OPCUA node in Node-red I am able to connect and access data but for accessing the alarms and events not getting what to do.
I have tested my OPCAE server with the OPC expert tool and it's working fine but I want to execute alarms and events with Node-red.
Please help me out regarding this issue.
Thank you.
I havenĀ“t worked with alarms and events yet but you or other people interessted may have a look on this discusion.
OPCUA-TEST-NODES.json contains an examples for testing events:
[
{
"id": "6413368d70ce7daa",
"type": "tab",
"label": "Test Nodes",
"disabled": false
},
{
"id": "42ce521b1148624d",
"type": "OpcUa-Event",
"z": "6413368d70ce7daa",
"root": "ns=0;i=2253",
"eventtype": "i=2041",
"name": "Events",
"x": 570,
"y": 480,
"wires": [
[
"59e10624d8d6798b",
"7bc93ab21da004f4"
]
]
},
{
"id": "50afc9882c32c9b1",
"type": "inject",
"z": "6413368d70ce7daa",
"name": "Test Events",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "",
"topic": "",
"payload": "",
"payloadType": "str",
"x": 370,
"y": 480,
"wires": [
[
"42ce521b1148624d"
]
]
},
{
"id": "59e10624d8d6798b",
"type": "OpcUa-Client",
"z": "6413368d70ce7daa",
"endpoint": "bb039652.dcf5a8",
"action": "events",
"deadbandvalue": "",
"time": 10,
"timeUnit": "s",
"localfile": "",
"localkeyfile": "",
"securitymode": "None",
"securitypolicy": "None",
"folderName4PKI": "",
"name": "A & C",
"x": 730,
"y": 480,
"wires": [
[
"47d20f3e7618f5db"
]
]
},
{
"id": "9598544e1e208e0c",
"type": "OpcUa-Client",
"z": "6413368d70ce7daa",
"endpoint": "bb039652.dcf5a8",
"action": "acknowledge",
"deadbandtype": "a",
"deadbandvalue": "5",
"time": "1",
"timeUnit": "s",
"localfile": "",
"localkeyfile": "",
"securitymode": "None",
"securitypolicy": "None",
"name": "ProSys NONE",
"x": 1060,
"y": 580,
"wires": [
[]
]
},
{
"id": "47d20f3e7618f5db",
"type": "debug",
"z": "6413368d70ce7daa",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 890,
"y": 480,
"wires": []
},
{
"id": "9a7458deff86b3b0",
"type": "inject",
"z": "6413368d70ce7daa",
"name": "Test Events",
"repeat": "",
"crontab": "",
"once": false,
"topic": "",
"payload": "",
"payloadType": "str",
"x": 370,
"y": 580,
"wires": [
[
"d02ed4a7087a2cd8"
]
]
},
{
"id": "d02ed4a7087a2cd8",
"type": "function",
"z": "6413368d70ce7daa",
"name": "AlarmID and EventID",
"func": "var msg;\nmsg.topic = \"ns=6;s=MyLevel.Alarm\";\nmsg.conditionId = \"ns=6;s=MyLevel.Alarm/0:EventId\";\nmsg.comment = \"Node-RED OPCUA Ack\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 630,
"y": 580,
"wires": [
[
"9598544e1e208e0c"
]
]
},
{
"id": "7bc93ab21da004f4",
"type": "debug",
"z": "6413368d70ce7daa",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 730,
"y": 440,
"wires": []
},
{
"id": "bb039652.dcf5a8",
"type": "OpcUa-Endpoint",
"endpoint": "opc.tcp://H7Q8Q13.vstage.co:53530/OPCUA/SimulationServer",
"secpol": "None",
"secmode": "None",
"login": false
}
]
{
"id": "7bc93ab21da004f4",
"type": "debug",
"z": "6413368d70ce7daa",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 730,
"y": 440,
"wires": []
},
{
"id": "bb039652.dcf5a8",
"type": "OpcUa-Endpoint",
"endpoint": "opc.tcp://H7Q8Q13.vstage.co:53530/OPCUA/SimulationServer",
"secpol": "None",
"secmode": "None",
"login": false
},
{
"id": "85144921.8931b8",
"type": "ui_group",
"name": "OPCUA",
"tab": "440c46c6.769ab8",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "440c46c6.769ab8",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
Related
I'm creating an Interactive Floor Plan using Node-RED (with Dashboard and "node-red-contrib-ui-svg"
My problem: I want a Website-popup in the Node-RED Dashboard by clicking on an information icon but i don't know how to create the popup. I tryed it with the "http in", "http request", "http response" and function nodes, but it didn't work. Maybe i just don't get the payload right?
By clicking on the SVG, a event is starting and the SVG Node sends a payload to the output.
Later there should be multiple events with different SVGs opening different URL-popups
Does someone know, if it is possible to create a popup in the Node-RED Dashboard and if yes, tell me how i can do it?
Here is a small example flow of what i tried:
[
{
"id": "213370b.a1a7e9",
"type": "tab",
"label": "Floorplan",
"disabled": false,
"info": ""
},
{
"id": "3a8acfc1.2d033",
"type": "debug",
"z": "213370b.a1a7e9",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 570,
"y": 100,
"wires": []
},
{
"id": "3d085e29.713452",
"type": "http in",
"z": "213370b.a1a7e9",
"name": "googl",
"url": "svg",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 90,
"y": 100,
"wires": [
[
"3e9f0610.1b40da"
]
]
},
{
"id": "7e8c6b26.c6b194",
"type": "http response",
"z": "213370b.a1a7e9",
"name": "",
"statusCode": "",
"headers": {},
"x": 570,
"y": 60,
"wires": []
},
{
"id": "e6a43abb.2208c8",
"type": "function",
"z": "213370b.a1a7e9",
"name": "",
"func": "msg.responseUrl=msg.payload;\nmsg.payload=msg.payload\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 450,
"y": 80,
"wires": [
[
"7e8c6b26.c6b194",
"3a8acfc1.2d033"
]
]
},
{
"id": "3e9f0610.1b40da",
"type": "http request",
"z": "213370b.a1a7e9",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": false,
"url": "nodered.org",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 270,
"y": 100,
"wires": [
[
"e6a43abb.2208c8"
]
]
},
{
"id": "2360d5fd.e4dc9a",
"type": "ui_svg_graphics",
"z": "213370b.a1a7e9",
"group": "ff128f4a.e252",
"order": 1,
"width": 0,
"height": 0,
"svgString": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0\" y=\"0\" height=\"100\" viewBox=\"0 0 100 100\" width=\"100\"><rect id=\"svgEditorBackground\" x=\"0\" y=\"0\" width=\"100\" height=\"100\" style=\"fill:none; stroke: none;\"/><defs id=\"svgEditorDefs\"><symbol id=\"2139\" viewBox=\"0 0 64 64\" preserveAspectRatio=\"xMidYMid meet\"><rect x=\"0\" y=\"0\" width=\"64\" height=\"64\" style=\"stroke:none;fill:none;\"/><g xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"32\" cy=\"32\" fill=\"#42ade2\" r=\"30\"/><g fill=\"#fff\"><path d=\"m36.51 25h-6.992c-2.633 0-5.145 1.05-5.584 2.333-.436 1.284.447 2.334 1.965 2.334s2.072 2.02 1.23 4.492l-4.889 14.349c-.844 2.471.619 4.492 3.252 4.492h6.992c2.633 0 5.143-1.051 5.582-2.333.436-1.283-.447-2.335-1.963-2.335-1.518 0-2.072-2.02-1.23-4.491l4.889-14.349c.843-2.47-.619-4.492-3.252-4.492\"/><path d=\"m36.29 11c-2.666 0-5.406 2.238-6.121 5-.717 2.761.869 4.999 3.533 4.999 2.668 0 5.408-2.238 6.123-4.999.717-2.763-.867-5-3.535-5\"/></g></g></symbol><polygon id=\"svgEditorIconDefs\" style=\"fill:rosybrown;\"/></defs><use xlink:href=\"#2139\" x=\"4.410\" y=\"4.552\" width=\"19.061\" height=\"19.061\" id=\"svg_i\" transform=\"matrix(1.87014 0 0 1.87014 -2.59955 -2.72311)\"/></svg>",
"clickableShapes": [
{
"targetId": "#svg_i",
"action": "click",
"payload": "http://www.google.com",
"payloadType": "str",
"topic": "#svg_i"
}
],
"smilAnimations": [],
"bindings": [],
"showCoordinates": false,
"autoFormatAfterEdit": false,
"showBrowserErrors": false,
"outputField": "payload",
"editorUrl": "//drawsvg.org/drawsvg.html",
"directory": "",
"panning": "disabled",
"zooming": "disabled",
"panOnlyWhenZoomed": false,
"doubleClickZoomEnabled": false,
"mouseWheelZoomEnabled": false,
"name": "",
"x": 120,
"y": 60,
"wires": [
[
"e6a43abb.2208c8"
]
]
},
{
"id": "ff128f4a.e252",
"type": "ui_group",
"z": "",
"name": "SVG",
"tab": "9f9846f6.57ce98",
"order": 1,
"disp": true,
"width": "23",
"collapse": false
},
{
"id": "9f9846f6.57ce98",
"type": "ui_tab",
"z": "",
"name": "Background",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
If you are still searching a solution, "modal dialog" is what you are looking for. Try this:
https://discourse.nodered.org/t/how-to-show-modal-dialog-in-template-node/611/8
I'm building a monitoring stack for our internal projects. I would like for them to be able to design their own monitoring dashboards to be used inside Grafana so I cannot predict what those will be called.
I created a folder called grafana_dashboard, where I will be instructing them to store their dashboard as JSON files and I want to pass all the contents of that folder to the Grafana instance.
I have tried a number of variations of this :
resource "grafana_dashboard" "dashboards" {
for_each = fileset(path.module, "grafana_dashboard/*.json")
config_json = "${each.key}"
depends_on = [aiven_service.grafana]
}
But keep getting this error:
Error: invalid character 'g' looking for beginning of value
on ../modules/monitoring/grafana.tf line 139, in resource "grafana_dashboard" "dashboards":
139: resource "grafana_dashboard" "dashboards" {
Can any of you see what I'm doing wrong?
Here's an example of one of the .json files i'm trying to pass:
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
},
{
"datasource": "Prometheus",
"enable": true,
"expr": "sum(changes(nginx_ingress_controller_config_last_reload_successful_timestamp_seconds{instance!=\"unknown\",controller_class=~\"$controller_class\",namespace=~\"$namespace\"}[30s])) by (controller_class)",
"hide": false,
"iconColor": "rgba(255, 96, 96, 1)",
"limit": 100,
"name": "Config Reloads",
"showIn": 0,
"step": "30s",
"tagKeys": "controller_class",
"tags": [],
"titleFormat": "Config Reloaded",
"type": "tags"
}
]
},
"description": "Ingress-nginx supports a rich collection of prometheus metrics. If you have prometheus and grafana installed on your cluster then prometheus will already be scraping this data due to the scrape annotation on the deployment.",
"editable": false,
"gnetId": 9614,
"graphTooltip": 0,
"id": 18,
"iteration": 1574177838584,
"links": [],
"panels": [
{
"columns": [
{
"text": "Current",
"value": "current"
}
],
"datasource": "Prometheus",
"fontSize": "100%",
"gridPos": {
"h": 15,
"w": 24,
"x": 0,
"y": 0
},
"height": "1024",
"id": 85,
"links": [],
"options": {},
"pageSize": 15,
"scroll": true,
"showHeader": true,
"sort": {
"col": 1,
"desc": false
},
"styles": [
{
"alias": "Time",
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"pattern": "Time",
"type": "date"
},
{
"alias": "TTL",
"colorMode": "cell",
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Current",
"thresholds": [
"0",
"691200"
],
"type": "number",
"unit": "s"
},
{
"alias": "",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"decimals": 2,
"pattern": "/.*/",
"thresholds": [],
"type": "number",
"unit": "short"
}
],
"targets": [
{
"expr": "avg(nginx_ingress_controller_ssl_expire_time_seconds{kubernetes_pod_name=~\"$controller\",namespace=~\"$namespace\",ingress=~\"$ingress\"}) by (host) - time()",
"format": "time_series",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ host }}",
"metric": "gke_letsencrypt_cert_expiration",
"refId": "A",
"step": 1
}
],
"title": "Ingress Certificate Expiry",
"transform": "timeseries_aggregations",
"type": "table"
}
],
"refresh": "5s",
"schemaVersion": 19,
"style": "dark",
"tags": [
"nginx"
],
"templating": {
"list": [
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Namespace",
"multi": false,
"name": "namespace",
"options": [],
"query": "label_values(nginx_ingress_controller_config_hash, controller_namespace)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Controller Class",
"multi": false,
"name": "controller_class",
"options": [],
"query": "label_values(nginx_ingress_controller_config_hash{namespace=~\"$namespace\"}, controller_class) ",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Controller",
"multi": false,
"name": "controller",
"options": [],
"query": "label_values(nginx_ingress_controller_config_hash{namespace=~\"$namespace\",controller_class=~\"$controller_class\"}, controller_pod) ",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Ingress",
"multi": false,
"name": "ingress",
"options": [],
"query": "label_values(nginx_ingress_controller_requests{namespace=~\"$namespace\",controller_class=~\"$controller_class\",controller=~\"$controller\"}, ingress) ",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 2,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-5m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"2m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "browser",
"title": "Cert-manager",
"uid": "nginx",
"version": 12
}
This works, so I know that I can do it, but doesn't suit my needs as I'd need to hardcode the name of each file:
resource "grafana_dashboard" "nginx_ingress_controller" {
config_json = templatefile("${path.module}/grafana_dashboard/nginx-ingress-controller.json", { DS_PROMETHEUS = local.prometheus_datasource_name })
depends_on = [aiven_service.grafana]
}
You need to actually use the file contents in your config_json parameter to the grafana_dashboard.
Switching your resource definition to the following should be enough:
resource "grafana_dashboard" "dashboards" {
for_each = fileset(path.module, "grafana_dashboard/*.json")
config_json = file("${path.module}/${each.key}")
depends_on = [aiven_service.grafana]
}
red-contrib-mqtt-broker` as mqtt broker. connection/disconnection of clients, are happening fine but in backend sockets are not getting closed immediately so sockets getting pileup.and its leading to server down.
please help me how to resolve this issue.
here is my node-red flow
[
{
"checkall": "false",
"id": "75e2813d.1200d",
"name": "chkTopic",
"outputs": 3,
"property": "topic",
"propertyType": "msg",
"repair": false,
"rules": [
{
"t": "eq",
"v": "clientConnected",
"vt": "str"
},
{
"t": "eq",
"v": "published",
"vt": "str"
},
{
"t": "eq",
"v": "clientDisconnected",
"vt": "str"
}
],
"type": "switch",
"wires": [
[
"e44d3fd.601fcc"
],
[
"b0cbe2f0.fdf51"
],
[
"352b1527.c0382a"
]
],
"x": 340,
"y": 120,
"z": "9207591e.000228"
},
{
"dburl": "",
"id": "169a1574.037e8b",
"mqtt_port": "6883",
"mqtt_ws_port": "6889",
"name": "Silsung ST Connector",
"password": "ajay1234",
"type": "mosca in",
"username": "admin",
"wires": [
[
"75e2813d.1200d"
]
],
"x": 140,
"y": 120,
"z": "9207591e.000228"
},
{
"active": true,
"complete": "payload",
"console": false,
"id": "b0cbe2f0.fdf51",
"name": "",
"tosidebar": true,
"tostatus": false,
"type": "debug",
"wires": [],
"x": 530,
"y": 120,
"z": "9207591e.000228"
},
{
"active": true,
"complete": "payload",
"console": false,
"id": "352b1527.c0382a",
"name": "",
"tosidebar": true,
"tostatus": false,
"type": "debug",
"wires": [],
"x": 530,
"y": 180,
"z": "9207591e.000228"
},
{
"active": true,
"complete": "payload",
"console": false,
"id": "e44d3fd.601fcc",
"name": "",
"tosidebar": true,
"tostatus": false,
"type": "debug",
"wires": [],
"x": 510,
"y": 60,
"z": "9207591e.000228"
}
]
I'm trying to use fcm-push to send a notification to Android. I'm just not sure how to build the flow.
I've successfully made Firebase send a notification to android via the firebase console.
just need an example flow for fcm-push.
thanks.
After much trial and error - I was able to come up with this. I did copy and then modify another example - unfortunately I don't know where the final example came from that I got to work (sorry). Here is one that is working, you can "import" into Node Red. Remember to change the AuthKey to your own.
[
{
"id": "b765ca96.a1ef58",
"type": "tab",
"label": "Flow 1 _ send notifications to FCM",
"disabled": false,
"info": ""
},
{
"id": "6ecb45a9.373ddc",
"type": "inject",
"z": "b765ca96.a1ef58",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"x": 120,
"y": 40,
"wires": [
[
"aafc8341.84eae"
]
]
},
{
"id": "3aab90c5.6c2a4",
"type": "http request",
"z": "b765ca96.a1ef58",
"name": "http POST to Google FCM",
"method": "POST",
"ret": "txt",
"url": "https:\/\/fcm.googleapis.com\/fcm\/send",
"tls": "",
"x": 180,
"y": 220,
"wires": [
[
"8d1dc739.0b7ac8"
]
]
},
{
"id": "aafc8341.84eae",
"type": "function",
"z": "b765ca96.a1ef58",
"name": "set payload and headers",
"func": "msg.payload = {\"to\": \"\/topics\/news\",\"data\": {\"message\": \"This is a FCM Topic Message!\"},\"notification\":{\"body\" : \"some_message\"}};\nmsg.headers = {\"Authorization\": \"key=BDzaSyCN932874928374-d1Jz3Rkcvbcr4\"};\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 170,
"y": 120,
"wires": [
[
"3aab90c5.6c2a4"
]
]
},
{
"id": "8d1dc739.0b7ac8",
"type": "debug",
"z": "b765ca96.a1ef58",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"complete": "false",
"x": 290,
"y": 340,
"wires": [
]
}
]
I have following tfstate file (it has JSON structure)
{
"version": 3,
"terraform_version": "0.11.1",
"serial": 1,
"lineage": "4d050905-8f3d-46df-8bbb-8859c708abe7",
"modules": [
{
"path": [
"root"
],
"outputs": {
"id": {
"sensitive": false,
"type": "list",
"value": [
"34.244.138.72",
"34.249.95.222"
]
}
},
"resources": {
"aws_instance.win-example.0": {
"type": "aws_instance",
"depends_on": [
"aws_security_group.DJukes"
],
"primary": {
"id": "i-0f8c0fcb36f58947d",
"attributes": {
"ami": "ami-cc821eb5",
"associate_public_ip_address": "true",
"availability_zone": "eu-west-1a",
"disable_api_termination": "false",
"ebs_block_device.#": "0",
"ebs_optimized": "false",
"ephemeral_block_device.#": "0",
"iam_instance_profile": "",
"id": "i-0f8c0fcb36f58947d",
"instance_state": "running",
"instance_type": "t2.medium",
"ipv6_addresses.#": "0",
"key_name": "",
"monitoring": "false",
"network_interface.#": "0",
"network_interface_id": "eni-8dbf17be",
"placement_group": "",
"primary_network_interface_id": "eni-8dbf17be",
"private_dns": "ip-172-31-30-138.eu-west-1.compute.internal",
"private_ip": "172.31.30.138",
"public_dns": "ec2-34-244-138-72.eu-west-1.compute.amazonaws.com",
"public_ip": "34.244.138.72",
"root_block_device.#": "1",
"root_block_device.0.delete_on_termination": "true",
"root_block_device.0.iops": "100",
"root_block_device.0.volume_id": "vol-0dcfa45e001323eac",
"root_block_device.0.volume_size": "30",
"root_block_device.0.volume_type": "gp2",
"security_groups.#": "1",
"security_groups.4272775738": "DJukes",
"source_dest_check": "true",
"subnet_id": "subnet-5b50a512",
"tags.%": "1",
"tags.Name": "DJukes-1",
"tenancy": "default",
"user_data": "fad67bb12b32d15c3f5156bf7bdd830d4e084c6f",
"volume_tags.%": "0",
"vpc_security_group_ids.#": "1",
"vpc_security_group_ids.2187737336": "sg-fd5adf87"
},
"meta": {
"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
"create": 600000000000,
"delete": 600000000000,
"update": 600000000000
},
"schema_version": "1"
},
"tainted": false
},
"deposed": [],
"provider": "provider.aws"
},
"aws_instance.win-example.1": {
"type": "aws_instance",
"depends_on": [
"aws_security_group.DJukes"
],
"primary": {
"id": "i-0bb714a7ddd376599",
"attributes": {
"ami": "ami-cc821eb5",
"associate_public_ip_address": "true",
"availability_zone": "eu-west-1a",
"disable_api_termination": "false",
"ebs_block_device.#": "0",
"ebs_optimized": "false",
"ephemeral_block_device.#": "0",
"iam_instance_profile": "",
"id": "i-0bb714a7ddd376599",
"instance_state": "running",
"instance_type": "t2.medium",
"ipv6_addresses.#": "0",
"key_name": "",
"monitoring": "false",
"network_interface.#": "0",
"network_interface_id": "eni-dab018e9",
"placement_group": "",
"primary_network_interface_id": "eni-dab018e9",
"private_dns": "ip-172-31-24-177.eu-west-1.compute.internal",
"private_ip": "172.31.24.177",
"public_dns": "ec2-34-249-95-222.eu-west-1.compute.amazonaws.com",
"public_ip": "34.249.95.222",
"root_block_device.#": "1",
"root_block_device.0.delete_on_termination": "true",
"root_block_device.0.iops": "100",
"root_block_device.0.volume_id": "vol-079b3491295b06249",
"root_block_device.0.volume_size": "30",
"root_block_device.0.volume_type": "gp2",
"security_groups.#": "1",
"security_groups.4272775738": "DJukes",
"source_dest_check": "true",
"subnet_id": "subnet-5b50a512",
"tags.%": "1",
"tags.Name": "DJukes-2",
"tenancy": "default",
"user_data": "fad67bb12b32d15c3f5156bf7bdd830d4e084c6f",
"volume_tags.%": "0",
"vpc_security_group_ids.#": "1",
"vpc_security_group_ids.2187737336": "sg-fd5adf87"
},
"meta": {
"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
"create": 600000000000,
"delete": 600000000000,
"update": 600000000000
},
"schema_version": "1"
},
"tainted": false
},
"deposed": [],
"provider": "provider.aws"
},
"aws_security_group.DJukes": {
"type": "aws_security_group",
"depends_on": [],
"primary": {
"id": "sg-fd5adf87",
"attributes": {
"description": "Managed by Terraform",
"egress.#": "1",
"egress.482069346.cidr_blocks.#": "1",
"egress.482069346.cidr_blocks.0": "0.0.0.0/0",
"egress.482069346.description": "",
"egress.482069346.from_port": "0",
"egress.482069346.ipv6_cidr_blocks.#": "0",
"egress.482069346.prefix_list_ids.#": "0",
"egress.482069346.protocol": "-1",
"egress.482069346.security_groups.#": "0",
"egress.482069346.self": "false",
"egress.482069346.to_port": "0",
"id": "sg-fd5adf87",
"ingress.#": "1",
"ingress.2601213444.cidr_blocks.#": "1",
"ingress.2601213444.cidr_blocks.0": "0.0.0.0/0",
"ingress.2601213444.description": "",
"ingress.2601213444.from_port": "0",
"ingress.2601213444.ipv6_cidr_blocks.#": "0",
"ingress.2601213444.protocol": "tcp",
"ingress.2601213444.security_groups.#": "0",
"ingress.2601213444.self": "false",
"ingress.2601213444.to_port": "6556",
"name": "DJukes",
"owner_id": "520150089049",
"revoke_rules_on_delete": "false",
"tags.%": "1",
"tags.Name": "allow-RDP",
"vpc_id": "vpc-8b23ccec"
},
"meta": {
"schema_version": "1"
},
"tainted": false
},
"deposed": [],
"provider": "provider.aws"
}
},
"depends_on": []
}
]
I want to extract public IP addresses to variables using python
"value": [
"34.244.138.72",
"34.249.95.222"
]
So far, i have following code:
#!/bin/python
import json
import os.path
import shutil
from os import mkdir
from pprint import pprint
from python_terraform import *
json_data=open('./terraform.json')
data = json.load(json_data)
json_data.close()
for i in range (0, len (data['modules'])):
print data['modules']['path']['outputs'][1]
And getting following error:
File "./1.py", line 17, in <module>
for i in range (0, len (data['modules']['path']['outputs'])):
TypeError: list indices must be integers, not str
also tried:
for dat in data:
print dat['outputs']
We can see from your JSON that modules is a list, which maps to an array with numeric indices, not a dictionary. (Though, there seems to be only one item in the list.)
So you need to iterate over it with i.
See what you are actually receiving with something like:
for i in range (0, len (data['modules'])):
pprint(data['modules'][i]['outputs']['id']['value'])
Which outputs:
$ python 1.py
[u'34.244.138.72', u'34.249.95.222']