influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.44k stars 5.55k forks source link

[inputs.opcua] Error in plugin #10700

Closed fjcanoGPT closed 2 years ago

fjcanoGPT commented 2 years ago

Telegraf using opcua plugin, trying to connect to Raspberry Pi - Codesys Control OPC UA Server. Getting Unknown error:

Error:

sudo telegraf --config telegraf.conf 2022-02-22T12:09:17Z I! Starting Telegraf 1.21.3 2022-02-22T12:09:17Z I! Loaded inputs: opcua 2022-02-22T12:09:17Z I! Loaded aggregators: 2022-02-22T12:09:17Z I! Loaded processors: 2022-02-22T12:09:17Z I! Loaded outputs: influxdb 2022-02-22T12:09:17Z I! Tags enabled: host=raspberrypi 2022-02-22T12:09:17Z I! [agent] Config: Interval:1s, Quiet:false, Hostname:"raspberrypi", Flush Interval:10s 2022-02-22T12:09:17Z W! [inputs.opcua] Failed to load certificate: open /etc/telegraf/cert.pem: no such file or directory 2022-02-22T12:09:18Z I! error encrypting user password: x509: invalid basic constraints b 2022-02-22T12:09:18Z E! [inputs.opcua] Error in plugin: error in Client Connection: x509: invalid basic constraints b

Telegraf.conf

[[inputs.opcua]]
  ## Metric name
  name = "opcua"
  #
  ## OPC UA Endpoint URL
  endpoint = "opc.tcp://127.0.0.1:4840"
  #
  ## Maximum time allowed to establish a connect to the endpoint.
  connect_timeout = "10s"
  #
  ## Maximum time allowed for a request over the estabilished connection.
  request_timeout = "5s"
  #
  ## Security policy, one of "None", "Basic128Rsa15", "Basic256",
  ## "Basic256Sha256", or "auto"
  security_policy = "None"
  #
  ## Security mode, one of "None", "Sign", "SignAndEncrypt", or "auto"
  security_mode = "None"
  #
  ## Path to cert.pem. Required when security mode or policy isn't "None".
  ## If cert path is not supplied, self-signed cert and key will be generated.
  #certificate = "OPCUAServer@raspberrypi.cer"
  #
  ## Path to private key.pem. Required when security mode or policy isn't "None".
  ## If key path is not supplied, self-signed cert and key will be generated.
  # private_key = "/etc/telegraf/key.pem"
  #
  ## Authentication Method, one of "Certificate", "UserName", or "Anonymous".  To
  ## authenticate using a specific ID, select 'Certificate' or 'UserName'
  auth_method = "UserName"
  #
  ## Username. Required for auth_method = "UserName"
  username = "admin"
  #
  ## Password. Required for auth_method = "UserName"
  password = "admin"
  #
  ## Option to select the metric timestamp to use. Valid options are:
  ##     "gather" -- uses the time of receiving the data in telegraf
  ##     "server" -- uses the timestamp provided by the server
  ##     "source" -- uses the timestamp provided by the source
  timestamp = "server"
  #
  ## Node ID configuration
  ## name              - field name to use in the output
  ## namespace         - OPC UA namespace of the node (integer value 0 thru 3)
  ## identifier_type   - OPC UA ID type (s=string, i=numeric, g=guid, b=opaque)
  ## identifier        - OPC UA ID (tag as shown in opcua browser)
  ## tags              - extra tags to be added to the output metric (optional)
  ## Example:
  ## {name="ProductUri", namespace="0", identifier_type="i", identifier="2262", tags=[["tag1","value1"],["tag2","value2]]}
  nodes = [
  {name="DB_STMX_0", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[0]"},
  {name="DB_STMX_1", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[1]"},
  {name="DB_STMX_2", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[2]"},
  {name="DB_STMX_3", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[3]"},
  {name="DB_STMX_4", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[4]"},
  {name="DB_STMX_5", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[5]"},
  {name="DB_STMX_6", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[6]"},
  {name="DB_STMX_7", namespace="4", identifier_type="s", identifier="|var|CODESYS Control for Raspberry Pi SL.Application.GVL_OPC.Read.DB_STMX[7]"},
  ] 

With python client just need configure user and admin to stablish connection

import opcua
import time

url = "opc.tcp://192.168.1.138:4840"

opc_client = opcua.Client(url)

opc_client.set_user("admin")
opc_client.set_password("admin")

opc_client.connect()

time.sleep(1)

opc_client.close_session()
telegraf-tiger[bot] commented 2 years ago

Hello! I recommend posting this question in our Community Slack or Community Page, we have a lot of talented community members there who could help answer your question more quickly. Heads up, this issue will be automatically closed after 7 days of inactivity. Thank you!

telegraf-tiger[bot] commented 2 years ago

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Page. Thank you!