---
title: roSnmpAgent
slug: develop/rosnmpagent
docTags: 
createdAt: 2025-03-26T17:24:32.566Z
---

When this object is created, it starts an SNMP process that handles some standard SNMP MIBs such as system uptime. Prior to starting th&#x65;*&#xA0;*&#x53;NMP agent, you can register other OIDs for handling. You can set and retrieve these by both an SNMP client and the script.

OID values are retrieved by an SNMP client without script interaction. Setting OID values will generate an *roSnmpEvent&#x20;*&#x6F;bject stating that they have been changed. The script event handler can then retrieve new values and take appropriate action.

Setting an OID value from an SNMP client doesn't block the client waiting on any script action; there is a short, but indeterminate, time delay for scripts to act on a value change. This isn't a problem generally because of the way SNMP MIBs are designed. If you want to provide constantly updating OID values, you can update them using either a timer or state changes.

The JavaScript equivalent is net-snmp.

The *roSnmpAgent&#xA0;*&#x6F;bject is created with an optional *roAssociativeArray:*

:::hint{type="info"}
agent = CreateObject("roSnmpAgent")
:::

As of BrightSignOS 8.3.20, the default parameters below can be provided on object construction. Note that when both ro\_community and rw\_community are set, they must be unique values. Otherwise, simply provide rw\_community:

- `ro_community` <font color="#6554c0">string</font> <font color="#00b8d9">optional</font>: Sets the read community string.
- `rw_community` <font color="#6554c0">string</font> <font color="#00b8d9">optional</font>: Sets the write community string.

## ifSnmpAgent

**AddOidHandler(oid\_string As String, writable\_flag As Boolean, initial\_value As Object) As Boolean**

Adds an OID handler with the following parameters to the SNMP agent:

- `oid_string`: The OID string (e.g. "1.3.6.1.4.1.26095.1.1.1.4.4.0"). All OID strings should be numerical.
- `writable_flag`: A Boolean value indicating whether the value can be changed by an SNMP client.
- `initial_value`: The initial value, which can be either an *roString&#xA0;*&#x6F;r *roInt*. The OID will reflect the type chosen here.


**GetOidValue(oid\_string As String) As Object**

Returns the current value (as either roString or roInt) for a given OID.

**SetOidValue(oid\_string As String, new\_value As Object) As Boolean**

Changes the current value for a given OID. The passed value can be either an roString or roInt.

**Start() As Boolean**

Starts the SNMP agent. Call this method once all OID handlers have been registered.

**Example**

```none
agent = CreateObject("roSnmpAgent")
agent.AddOidHandler("1.3.6.1.4.1.26095.1.1.1.4.4.0", false, "ValueOfOid")
agent.AddOidHandler("1.3.6.1.4.1.26095.1.1.1.4.5.0", true, 10)
agent.Start() 
```

## ifUserData

**SetUserData(user\_data As Object)**

Sets the user data that will be returned when events are raised.

**GetUserData() As Object**

Returns the user data that has previously been set via SetUserData(). It will return Invalid if no data has been set.

## ifMessagePort

**SetPort(port As roMessagePort)**

Posts messages of type *roSnmpEvent&#xA0;*&#x74;o the attached message port.

