# Best way to get only domain from a URL using command with Go template package

**URL:** <https://discourse.sensu.io/t/best-way-to-get-only-domain-from-a-url-using-command-with-go-template-package/3045>\
**Category:** Sensu Go\
**Tags:** sensu-go\
**Created:** [December 6, 2022, 6:52pm UTC](https://discourse.sensu.io/t/best-way-to-get-only-domain-from-a-url-using-command-with-go-template-package/3045 "2022-12-06T18:52:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daswars](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/daswars/32/510_2.png) [@daswars](https://discourse.sensu.io/u/daswars)\
**Post date:** [December 6, 2022, 6:52pm UTC](https://discourse.sensu.io/t/best-way-to-get-only-domain-from-a-url-using-command-with-go-template-package/3045/1 "2022-12-06T18:52:52Z")

</div>

Hello, I have a small problem and need your help.  
I used several URL in my check and now need here from only the domain:  
Here I found the following solution:

> <https://stackoverflow.com/questions/27696337/best-way-to-display-only-url-domain-using-jinja2/40397212#40397212>

But this is in Jinja and I can not get it to run in sensu.

```auto
# lables
# url: https://api.server.local.cloud:8443/test/health?details=true

```

here i need as result only:

```auto
api.server.local.cloud:8443

```

i the past i use a check like this

```auto
command: check_http -H {{ .labels.url }} -C {{ .labels.cert_check_warn | default "35" }},{{ .labels.cert_check_crit | default "15" }} --ssl --sni -f follow -vvv

```

to this here as example

```auto
command: check_http -H {{ .labels.url.rpartition("//")[-1].partition("/")[0] }} -C {{ .labels.cert_check_warn | default "35" }},{{ .labels.cert_check_crit | default "15" }} --ssl --sni -f follow -vvv

```

i only find less information and examples in the sensu docs:

> **[Tokens reference | Sensu Go 6.9](https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-schedule/tokens/#token-specification)**
>
> Use tokens in Sensu checks as placeholders that agents replace with entity data to fine-tune check attributes while reusing check definitions.

---

<div class="post-metadata">

**Author:** ![aaronsachs](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/aaronsachs/32/47_2.png) [@aaronsachs](https://discourse.sensu.io/u/aaronsachs)\
**Post date:** [December 12, 2022, 4:05pm UTC](https://discourse.sensu.io/t/best-way-to-get-only-domain-from-a-url-using-command-with-go-template-package/3045/2 "2022-12-12T16:05:34Z")

</div>

Hi there,

A quick note–when posting code examples, please make sure you surround it with triple backticks like so:

```
```
code goes here
```
```

This helps make your snippets easier to read for the folks in the community who are seeing your post.

Re:

> But this is in Jinja and I can not get it to run in sensu.

There is no support in Sensu Go for Jinja2 templating. It uses Go templates, and Jinja2 (AFAIK) is a Python templating tool.

Can you elaborate as to what exactly you’re trying to accomplish by just extracting the URL without the HTTP scheme?

> i only find less information and examples in the sensu docs:

We certainly try to cover the most common use cases our users and customers run into–if this is something that you’d like to see more examples of, we’d welcome an issue on our [Docs repo](https://github.com/sensu/sensu-docs/issues/new?assignees=&labels=&template=content-issue.md&title=).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/sensu/original/1X/ad88ecc0d60777fbbb8dad05fe976fca2a4d87b2.jpeg) [@system](https://discourse.sensu.io/u/system)\
**Post date:** [January 11, 2023, 4:06pm UTC](https://discourse.sensu.io/t/best-way-to-get-only-domain-from-a-url-using-command-with-go-template-package/3045/3 "2023-01-11T16:06:15Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
