# SNMP inputs custom tag

**URL:** <https://community.influxdata.com/t/snmp-inputs-custom-tag/37025>\
**Category:** Telegraf\
**Tags:** telegraf\
**Created:** [September 16, 2024, 3:11pm UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025 "2024-09-16T15:11:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![romgo](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@romgo](https://community.influxdata.com/u/romgo)\
**Post date:** [September 16, 2024, 3:11pm UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/1 "2024-09-16T15:11:06Z")

</div>

Hello,

I am pretty much new to telegraf. Currently I have a bash script gathering some SNMP data from a remote host, and inject the results into influxDB with curl. This is working fine, but I wanted to migrate this script to telegraf instead.

My current script do something like :

```auto
UPTIME=$(snmpget -Oqv -v 2c -c community server sysptime)
/usr/bin/curl --silent --request POST 'http://127.0.0.1:8086/write?db=mydb' --data-binary 'uptime,host=server value='$UPTIME''

```

But with telegraf, I am able to get the data injected, but I’m not able to find a very simple way to add a tag with hostname of the server.

```auto
[[inputs.snmp]]
  agents = ["server:161"]
  community = "public"
[[inputs.snmp.field]]
    name = "uptime"
    oid = "sysuptime"

```

I tried different configuration like this one :

```auto
[[inputs.snmp]]
  agents = ["server:161"]
  community = "public"
[[inputs.snmp.field]]
    name = ["uptime", "server"]
    oid = "sysuptime"
    is_tag = true

```

but it doesn’t works.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [September 16, 2024, 3:20pm UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/2 "2024-09-16T15:20:11Z")

</div>

@romgo the host tag is usually automatically added if you didn’t set `omit_hostname = true` in the [`agent` section](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#agent) of your config…

---

<div class="post-metadata">

**Author:** ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)\
**Post date:** [September 16, 2024, 3:25pm UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/3 "2024-09-16T15:25:04Z")

</div>

There’s also the `agent_host` tag by default. (run telegraf with `--test` to see what’s actually collected)

You can also retrieve the hostname from the snmp device using this example:

```toml
  [[inputs.snmp.field]]
    oid = "RFC1213-MIB::sysUpTime.0"
    name = "sysUptime"
    conversion = "float(2)"

  [[inputs.snmp.field]]
    oid = "RFC1213-MIB::sysName.0"
    name = "sysName"
    is_tag = true

```

Adding a fixed tag is possible by adding this:

```toml
  [inputs.snmp.tags]
    server = "my hostname"

```

---

<div class="post-metadata">

**Author:** ![romgo](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@romgo](https://community.influxdata.com/u/romgo)\
**Post date:** [September 16, 2024, 3:30pm UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/4 "2024-09-16T15:30:27Z")

</div>

I use telegraf 1.31.3, my conf :

```auto
root@server ~ cat /etc/telegraf/telegraf.conf | grep omit
  omit_hostname = false

```

but when I query th data I don’t see the hostname ?

```auto
> select gpu_core_temp from "snmp" limit 10;
name: snmp
time gpu_core_temp
---- -------------
1726476285000000000 28
1726476290000000000 28
1726476300000000000 28
1726476310000000000 28
1726476320000000000 28
1726476330000000000 28
1726476340000000000 28
1726476350000000000 28
1726476360000000000 28
1726476370000000000 28

```

thanks !

---

<div class="post-metadata">

**Author:** ![srebhan](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/srebhan/32/8572_2.png) [@srebhan](https://community.influxdata.com/u/srebhan)\
**Post date:** [September 16, 2024, 6:46pm UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/5 "2024-09-16T18:46:18Z")

</div>

Well if you only select one field you will only see that field… 😃 Try

```auto
> select * from "snmp" limit 10;

```

---

<div class="post-metadata">

**Author:** ![romgo](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@romgo](https://community.influxdata.com/u/romgo)\
**Post date:** [September 17, 2024, 7:52am UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/6 "2024-09-17T07:52:14Z")

</div>

thank you !  
Indeed this was a PEBKAC issue ! Sorry 😅  
I have a field agent\_host which do the job :

> select gpu\_fan\_speed,agent\_host from “snmp” limit 10

side question : is there any good practice with regards on how to organize data within databases ?  
currently my snmp database mix various data coming from snmp, could this be an issue some how ?

Regards

---

<div class="post-metadata">

**Author:** ![Hipska](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/hipska/32/3877_2.png) [@Hipska](https://community.influxdata.com/u/Hipska)\
**Post date:** [September 17, 2024, 7:57am UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/7 "2024-09-17T07:57:24Z")

</div>

That’s why I said to use `--test`, then you see what metrics actually would be sent to InfluxDB.

It’s not really a database like you know ‘relational’ databases, it’s a ‘time series’ database; so you have a bucket, with metrics (in this case you name it `snmp`) which can have different tags and fields. There’s no big issue with that, depending on how you query your data afterwards.

If you’re just beginning with snmp and telegraf, I advise to also look at this blog post: [Telegraf Best Practices: SNMP Plugin | InfluxData](https://www.influxdata.com/blog/telegraf-best-practices-snmp-plugin/)

---

<div class="post-metadata">

**Author:** ![romgo](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@romgo](https://community.influxdata.com/u/romgo)\
**Post date:** [September 17, 2024, 8:05am UTC](https://community.influxdata.com/t/snmp-inputs-custom-tag/37025/8 "2024-09-17T08:05:53Z")

</div>

> [@Hipska](#):
>
> post

Thank you.  
I did give a try with --test, but I got too much data, and I was note sure that this will no affect current running telegraf service.

I will review the blog post thanks.
