FreeNAS Stat Monitor

Pretty simple sensors for FreeNAS stat monitoring.

config.yaml

sensor:
  - platform: rest
    name: FN_trunk_report
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://hostipaddress/api/v1.0/storage/volume/trunk/?format=json
    value_template: '{{ value_json.status }}'
    username: !secret fn_user
    password: !secret fn_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: template
    sensors:
      fn_trunk_pct_used:
        value_template: '{{ states.sensor.fn_trunk_report.attributes["used_pct"].title() }}'
        entity_id: sensor.fn_trunk_report
      
  - platform: rest
    name: FN_alert_level
    resource: http://hostipaddress/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json[0].level }}'
    username: !secret fn_user
    password: !secret fn_password
    authentication: basic
    headers:
      Content-Type: application/json
  
  - platform: rest
    name: FN_alert_message
    resource: http://hostipaddress/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json[0].message }}'
    username: !secret fn_user
    password: !secret fn_password
    authentication: basic
    headers:
      Content-Type: application/json
  
  - platform: rest
    name: FN_version
    json_attributes:
      - fullversion
      - name
      - version
    resource: http://hostipaddress/api/v1.0/system/version/?format=json
    value_template: '{{ value_json.fullversion }}'
    username: !secret fn_user
    password: !secret fn_password
    authentication: basic
    headers:
      Content-Type: application/json

groups.yaml

group:
  FreeNAS Server Monitor:
    view: no
    entities:
      - sensor.fn_version
      - sensor.fn_alert_level
      - sensor.fn_alert_message
      - sensor.fn_trunk_report
      - sensor.fn_trunk_pct_used
5 Likes

I must admit, I didn’t even realise there was an API available for freenas. I’ve added some information already such as CPU load, temperatures etc via SNMP but I like the idea of bringing in the alert messages into Home assistant.

Thanks for posting

Cool didnt know there was an API for FreeNAS. Been trying to do this with SNMP but had a lot of issues on the old 9.2 build so I stopped that project. Now I know there is an API I can monitor my NAS :slight_smile:

2 volumes over here, so 2x api call, to get info about the volume.

@gremblin, maybe also add the scan_interval so it will check on regular times and not overflood the api? My NAS is just serving some non-important things so i’m calling both sensors only 1x an hour.

scan_interval: 3600

Thanks @Bramus. Ha, I didn’t even know about SNMP. I might look into that, just out of curiousity.

Good point on the scan_interval. You’re not pulling any information that gets updated all that often, so it doesn’t make since to pull every minute (the default). I had orginally hoped for the CPU, Memory, Network traffic information so I could track all of that in one place (HA), but the FreeNAS API doesn’t expose that information. The built in graphing is pretty good, and if it did publish that information, it would probably be a little bit of a performance hit I suppose. But I usually want to go back in time and see how it was performing after the fact…

I did get that information for my pfSense router… and basically I found out that those values don’t change all that often. Which is good. Just not all that interesting to look at.

Thank you for your YAML code!
But … I got an error in my Hass log, and also got the value ‘Unknown’ in the sensor.fn_nas0_report and sensor.fn_nas0_pct_used. The other values and sensors are OK.

The error in the log is, each minute:

empty reply found when expecting JSON data’
and
error parsing value: ‘value_json’ is undefined (value: , template: {{ value_json.status }})

What’s going wrong? The api information is visable when I call the api in my browser. And I copied your yaml code exacty (changed the ip adress of course). Should I rename ‘nas0’? What should it be?

In your groups.yaml:

Replace

  - sensor.fn_nas0_report
  - sensor.fn_nas0_pct_used

with

  - sensor.fn_trunk_report
  - sensor.fn_trunk_pct_used
1 Like

Also in:

http://hostipaddress/api/v1.0/storage/volume/trunk/?format=json

‘trunk’ needs to be the name of your volume. I set it to ‘trunk’ because I think that’s the typical name set… but you could have set yours to anything.

1 Like

This is great! I always wanted to pull volume health, alerts etc into my Grafana dashboard but Graphite and SNMP doesn’t provide it. It works great!

You can pull CPU, Memory, and Network using Graphite but that’s assuming you want to visualize it in Grafana. My knowledge is limited with pulling that information into Home Assistant.

It was working great until now. I am receiving state unknown for alert level and alert message.

Any ideas?

@junior466 Can you give any information? What changed? You reboot FreeNAS? What does your FreeNAS UI say the alert level and message are? Have you tried pulling the API response from your browser to make sure the information is what you expect it to be? You mess with your HA Config at all? Are there log errors in HA? What troubleshooting steps have you done?

@gremblin I did reboot FreeNAS. My alert level and messages are clear/none. The API response is simply []. Home Assistant shows unknown for state for sensor.freenas_alert_level and sensor.freenas_alert_message (I changed my sensors name to freenas).

Nothing has changed in my configuration. It was working fine before rebooting FreeNAS.

@gremblin Forgot to add that Home Assistant shows:

Error parsing value: list object has no element 0 (value: [], template: {{ value_json[0].level }})

Nice work. Thank you for the post.

Here is something similar:
Home Assistant and FreeNAS

Hrm. Can you post you config? Also have you checked your url from the browser?

http://hostipaddress/api/v1.0/system/alert/?format=json

You should be prompted for a username and password. Also, if you have non ssl connections disabled, it may give you issues. Do you connect to your freenas via http or https?

@gremblin Here’s my config:

  - platform: rest
    name: FreeNAS_volume_report
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://MYIPADDRESS/api/v1.0/storage/volume/MY_VOLUME/?format=json
    value_template: '{{ value_json.status }}'
    username: root
    password: MYPASS
    authentication: basic
    scan_interval: 3600
    headers:
      Content-Type: application/json


  - platform: rest
    name: FreeNAS_alert_message
    resource: http://MYIPADDRESS/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json[0].message }}'
    username: root
    password: MYPASS
    authentication: basic
    scan_interval: 3600
    headers:
      Content-Type: application/json

  - platform: rest
    name: FreeNAS_alert_level
    resource: http://MYIPADDRESS/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json[0].level }}'
    username: root
    password: MYPASS
    scan_interval: 3600
    authentication: basic
    headers:
      Content-Type: application/json 

If I visit the address, the only thing I see is “[]”. I am also not prompted for a password. I don’t access freenas using https.

Your config looks good. It sounds like there is an issue on your FreeNAS side. Which version of FreeNAS are you running? They are doing some changes to the API for v11.2

The rewrite from the old API to the new middlewared continues. Once the API stabilizes and the rewrite is complete, api.freenas.org will be deprecated and replaced by the new API documentation. In the mean time, to see the API documentation for the new middleware, log into the new UI, click on the URL for the FreeNAS system in your browser’s location bar, and add /api/docs to the end of that URL. Blog Post

I’m running v11.1, v11.2 gave me issues with my Ubuntu VM.

@gremblin I am running v11.1 as well.

@gremblin I have a feeling I know what could be wrong. In your example, you have an alert for an update so that is why the sensor works in your case. When I had a critical alert when I first tried your config, it worked fine for me as well. It displayed Critical for level and showed the message about one of my hard disk’s temperature.

Now that is empty (no alerts), it doesn’t show anything so the status is unknown. I bet if you cleared that alert you would have the same issue.

facepalm OH YEAH! Right! Yes. It will be empty when all is well. Atleast your message will be. I thought the level would still show though. Mine is currently showing Level: OK, Msg: There is a new update available! Apply it in System -> Update tab. But my FreeNAS train is pointed to 11.2 Stable currently, even though I’ve reverted back to 11.1

But didn’t you say that your volume sensors were empty as well?

Volume sensor shows just fine. I may had a typo on the config before.

So isn’t there a way to map this unknown status to display CLEAR or something more user friendly?
By the way, Homeassistant also doesn’t like the empty state:

Error parsing value: list object has no element 0 (value: [], template: {{ value_json[0].level }})