/ August 29, 2021/ Articles, Fortigate/ 0 comments

I own an Fortigate 40F firewall and with SNMP it is possible to add sensors in Home Assistant. I did the same with the Untangle firewall, which i owned previously.
First of all enable SNMP in the Fortigate Firewall under System \ SNMP. Make sure you enable SNMPv2c and add you Home Assistant IP address as a trusted Host. Only ‘accept queries’ is enough to read the sensor data. SNMPv1 can be disabled.

Make sure SNMP is also enabled on the LAN interface from where you connect in the Fortigate.

I am using the follow configuration in sensor.yaml. Change your secrets to your own secrets.

  - platform: snmp
    name: 'Firewall Firmware Version'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.4.1.12356.101.4.1.1.0
    community: !secret firewall_snmp_community
    value_template: "{{ value.split(',')[0] }}"   
    version: '2c'
    scan_interval: 60
  - platform: snmp
    name: 'Firewall Uptime'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.2.1.1.3.0
    community: !secret firewall_snmp_community
    version: '2c'
    scan_interval: 60
    value_template: >-
      {% set time = (value | int) | int %}
      {% set minutes = ((time % 360000) / 6000) | int%}
      {% set hours = ((time % 8640000) / 360000) | int %}
      {% set days = (time / 8640000) | int %}
        {%- if time < 60 -%}
          Less then 1 min
          {%- else -%}
          {%- if days > 0 -%}
            {{ days }}d
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if days > 0 -%}
              {{ ' ' }}
            {%- endif -%}
            {{ hours }}hr
          {%- endif -%}
          {%- if minutes > 0 -%}
            {%- if days > 0 or hours > 0 -%}
              {{ ' ' }}
            {%- endif -%}
            {{ minutes }}min
          {%- endif -%}
        {%- endif -%}
  - platform: snmp
    name: 'Firewall WAN In'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.2.1.2.2.1.10.1
    community: !secret firewall_snmp_community
    version: '2c'
    scan_interval: 60
  - platform: snmp
    name: 'Firewall WAN Out'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.2.1.2.2.1.16.1
    community: !secret firewall_snmp_community
    version: '2c'
    scan_interval: 60
  - platform: statistics
    name: 'Firewall WAN In Stats'
    entity_id: sensor.firewall_wan_in
    sampling_size: 4
    max_age:
      hours: 24
  - platform: statistics
    name: 'Firewall WAN Out Stats'
    entity_id: sensor.firewall_wan_out
    sampling_size: 4
    max_age:
      hours: 24
  - platform: template
    sensors:
      firewall_internet_in_mbps:
        value_template: "{{ (state_attr('sensor.firewall_wan_in_stats','change_rate')|float*8*(state_attr('sensor.firewall_wan_in_stats', 'sampling_size')-1)/1000000)|round(2) }}"
        unit_of_measurement: 'MBps'
      firewall_internet_out_mbps:
        value_template: "{{ (state_attr('sensor.firewall_wan_out_stats','change_rate')|float*8*(state_attr('sensor.firewall_wan_out_stats', 'sampling_size')-1)/1000000)|round(2) }}"
        unit_of_measurement: 'MBps'
  - platform: snmp
    name: 'Firewall CPU Used Percentage'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.4.1.12356.101.4.1.3.0
    community: !secret firewall_snmp_community
    version: '2c'
    value_template: '{{ value | float }}'
    unit_of_measurement: '%'
    scan_interval: 60
  - platform: snmp
    name: 'Firewall Memory Used Percentage'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.4.1.12356.101.4.1.4.0
    community: !secret firewall_snmp_community
    version: '2c'
    value_template: '{{ value | float }}'
    unit_of_measurement: "%"
    scan_interval: 60
  - platform: snmp
    name: 'Firewall Session Count'
    host: !secret firewall_ip
    baseoid: 1.3.6.1.4.1.12356.101.4.1.8.0
    community: !secret firewall_snmp_community
    version: '2c'
    value_template: '{{ value | float }}'
    scan_interval: 60  

and if you like you can create a nice lovelace dashboard. I do have some customization in this card for my theme, but you can change this if you like.

 - type: entities
   style: |
    ha-card {
       box-shadow: var(--card-box-shadow);
       margin: 0px 14px 0px 14px;
     }
   show_header_toggle: false
   title: Firewall info
   entities:
     - entity: sensor.firewall_uptime
       name: Uptime
     - entity: sensor.firewall_firmware_version
       name: Huidige versie
       icon: mdi:cloud-check
 - type: 'custom:vertical-stack-in-card'
   style: |
    ha-card {
       box-shadow: var(--card-box-shadow);
       margin: 0px 14px 0px 14px;
     }
   cards:
   - type: 'custom:mini-graph-card'
     style: |
      ha-card {
         box-shadow: var(--card-box-shadow);
         margin: 0px 14px 0px 14px;
       }
     name: Session Count
     color_thresholds:
       - color: '#e45e65'
         value: 600
       - color: '#e0b400'
         value: 400
       - color: '#0da035'
         value: 0
     color_thresholds_transition: hard
     entities:
       - sensor.firewall_session_count
     group: false
     hour24: true
     line_width: 6
     points_per_hour: 1
     show:
       extrema: false
       fill: fade
       icon: true
       labels: false
       name: true
       state: true
   - type: horizontal-stack
     style: |
      ha-card {
         box-shadow: var(--card-box-shadow);
         margin: 0px 14px 0px 14px;
       }
     cards:
     - type: 'custom:mini-graph-card'
       style: |
        ha-card {
           box-shadow: var(--card-box-shadow);
           margin: 0px 14px 0px 14px;
         }
       name: CPU
       color_thresholds:
         - color: '#e45e65'
           value: 50
         - color: '#e0b400'
           value: 20
         - color: '#0da035'
           value: -1
       color_thresholds_transition: hard
       entities:
         - sensor.firewall_cpu_used_percentage
       group: false
       hour24: true
       line_width: 6
       points_per_hour: 1
       show:
         extrema: true
         fill: fade
         icon: true
         labels: false
         name: true
         state: true
     - type: 'custom:mini-graph-card'
       style: |
        ha-card {
           box-shadow: var(--card-box-shadow);
           margin: 0px 14px 0px 14px;
         }
       name: Memory Used
       color_thresholds:
         - color: '#e45e65'
           value: 80
         - color: '#e0b400'
           value: 60
         - color: '#0da035'
           value: 20
       color_thresholds_transition: hard
       entities:
         - sensor.firewall_memory_used_percentage
       group: false
       hour24: true
       line_width: 6
       points_per_hour: 1
       show:
         extrema: true
         icon: true
         labels: false
         name: true
       state: true  
   - type: horizontal-stack
     style: |
      ha-card {
         box-shadow: var(--card-box-shadow);
         margin: 0px 14px 0px 14px;
       }
     cards:
       - type: 'custom:mini-graph-card'
         style: |
          ha-card {
             box-shadow: var(--card-box-shadow);
             margin: 0px 14px 0px 14px;
           }
         name: Download
         color_thresholds:
           - color: '#e45e65'
             value: 10
           - color: '#e0b400'
             value: 5
           - color: '#0da035'
             value: -1
         color_thresholds_transition: hard
         entities:
           - sensor.firewall_internet_in_mbps
         group: false
         hour24: true
         line_width: 6
         points_per_hour: 1
         show:
           extrema: true
           fill: fade
           icon: true
           labels: false
           name: true
           state: true
       - type: 'custom:mini-graph-card'
         style: |
          ha-card {
             box-shadow: var(--card-box-shadow);
             margin: 0px 14px 0px 14px;
           }
         name: Upload
         color_thresholds:
           - color: '#e45e65'
             value: 2
           - color: '#e0b400'
             value: 1
           - color: '#0da035'
             value: -1
         color_thresholds_transition: hard
         entities:
           - sensor.firewall_internet_out_mbps
         group: false
         hour24: true
         line_width: 6
         points_per_hour: 1
         show:
           extrema: true
           icon: true
           labels: false
           name: true
         state: true    
 

The result 🙂

Share this Post

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*

four × three =