Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐️ new OPC UA resource pack #1224

Merged
merged 6 commits into from
May 30, 2023
Merged

⭐️ new OPC UA resource pack #1224

merged 6 commits into from
May 30, 2023

Conversation

chris-rock
Copy link
Member

@chris-rock chris-rock commented May 22, 2023

The new OPC UA resource pack allows you to connect to OPC UA server and to query the tree easily via MQL:

# gather all available namespaces 
opcua.namespaces { * }
opcua.namespaces: [
  0: {
    id: 0
    name: "http://opcfoundation.org/UA/"
  }
  1: {
    id: 1
    name: "urn:open62541.server.application"
  }
]

# gather root node
cnquery> opcua.root
opcua.root: opcua.node id="i=84" name="Root"


# gather all nodes
cnquery> opcua.nodes { name namespace.name }

# gather node with a specific id
cnquery> opcua.nodes.where (id == "i=2253")
opcua.nodes.where: [
  0: opcua.node id="i=2253" name="Server"
]

# gather details about the server
cnquery> opcua.server { * }
opcua.server: {
  buildInfo: {
    BuildDate: "2023-05-21T21:03:43.817369Z"
    BuildNumber: "May 20 2023 15:51:32"
    ManufacturerName: "open62541"
    ProductName: "open62541 OPC UA Server"
    ProductURI: "http://open62541.org"
    SoftwareVersion: "1.3.5-994-g5d73f0cc5"
  }
  node: opcua.node id="i=2253" name="Server"
  currentTime: 2023-05-22 08:28:30.625932 +0000 UTC
  state: "ServerStateRunning"
  startTime: 2023-05-21 21:03:43.834304 +0000 UTC
}

Follow ups that need to be implemented on top of this PR:

  • add support for authentication modes
  • certificate authentication
  • more testing with different server implementations
  • support querying multiple services with inventories

@github-actions

This comment has been minimized.

Copy link
Contributor

@czunker czunker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks @chris-rock

Only some minor comments.

apps/cnquery/cmd/builder/parse.go Outdated Show resolved Hide resolved
motor/discovery/opcua/resolver.go Outdated Show resolved Hide resolved
motor/discovery/opcua/resolver.go Outdated Show resolved Hide resolved
motor/discovery/opcua/resolver.go Outdated Show resolved Hide resolved
resources/packs/opcua/README.md Show resolved Hide resolved
resources/packs/opcua/opcua.go Outdated Show resolved Hide resolved
resources/packs/opcua/opcua.lr Outdated Show resolved Hide resolved
resources/packs/opcua/opcua.lr Outdated Show resolved Hide resolved
@czunker
Copy link
Contributor

czunker commented May 24, 2023

I tried to test this locally, with the Azure container image, but got an error:

cnquery shell opcua --endpoint opc.tcp://192.168.1.87:50000 --verbose                                                                                                     
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
DBG parsing asset asset-type=1 provider=OPCUA
→ discover related assets for 1 asset(s)
DBG run resolver resolver="OPC-UA Resolver" resolver-id=opc-ua
DBG establish motor connection
→ resolved assets resolved-assets=0
x could not connect to asset error="opcua: could not resolve address f31e50127436:50000" asset=
FTL could not resolve assets

The address is the one used inside the container:

opc.tcp://f31e50127436:50000/

To run the container, I used the command from the README in this PR. Any ideas?

@chris-rock
Copy link
Member Author

@czunker Yes, the problem is that the azure opc service returns a resolved url. This essentially highlights that the OPC UA endpoint discovery cannot be trusted for the initial connection. I adjust the code.

@chris-rock chris-rock force-pushed the chris-rock/opcua branch 2 times, most recently from 862672e to ea73194 Compare May 28, 2023 11:04
@czunker
Copy link
Contributor

czunker commented May 30, 2023

@czunker Yes, the problem is that the azure opc service returns a resolved url. This essentially highlights that the OPC UA endpoint discovery cannot be trusted for the initial connection. I adjust the code.

Works now:

cnquery> opcua.server { * }
opcua.server: {
  buildInfo: {
    BuildDate: "2023-04-21T11:03:38Z"
    BuildNumber: "1.4.371.86"
    ManufacturerName: "Microsoft"
    ProductName: "IoTEdge OPC UA PLC"
    ProductURI: "https://github.com/Azure/iot-edge-opc-plc.git"
    SoftwareVersion: "1.4.371.86+36dd5653af33ed6af874ef1334d1a98ac28295f3"
  }
  node: opcua.node id="i=2253" name="Server"
  currentTime: 2023-05-30 04:20:25.4249191 +0000 UTC
  state: "ServerStateRunning"
  startTime: 2023-05-30 04:17:20.8710742 +0000 UTC
}

Thanks @chris-rock

@vjeffrey vjeffrey merged commit 9405cd4 into main May 30, 2023
@vjeffrey vjeffrey deleted the chris-rock/opcua branch May 30, 2023 17:23
@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants