MKANET

Home Assistant Glances RESTful code

Jun 15th, 2023
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 10.73 KB | None | 0 0
  1. rest:
  2.   - resource: http://192.168.1.2:61208/api/3/all
  3.     sensor:
  4.       - name: "Titan TCPIP Listen"
  5.         value_template: '{{ value_json.connections.LISTEN }}'
  6.       - name: "Titan TCPIP Established"
  7.         value_template: '{{ value_json.connections.ESTABLISHED }}'
  8.       - name: "Titan CPU"
  9.         value_template: '{{ value_json.cpu.total | round (1) }}'
  10.         unit_of_measurement: "%"
  11.       - name: "Titan CPU User"
  12.         value_template: '{{ value_json.cpu.user | round (1) }}'
  13.         unit_of_measurement: "%"
  14.       - name: "Titan CPU System"
  15.         value_template: '{{ value_json.cpu.system | round (1) }}'
  16.         unit_of_measurement: "%"
  17.       - name: "Titan C Drive Read Bytes"
  18.         value_template: >-
  19.           {% set read_byte = value_json.diskio[0].read_bytes if value_json.diskio|length else none %}
  20.           {% set time_since = value_json.diskio[0].time_since_update if value_json.diskio|length else none %}
  21.           {% if (read_byte != None ) and (time_since != None ) %}
  22.             {{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
  23.           {% endif %}
  24.         unit_of_measurement: 'MB/s'
  25.       - name: "Titan C Drive Write Bytes"
  26.         value_template: >-
  27.           {% set write_byte = value_json.diskio[0].write_bytes if value_json.diskio|length else none %}
  28.           {% set time_since = value_json.diskio[0].time_since_update if value_json.diskio|length else none %}
  29.           {% if (write_byte != None ) and (time_since != None ) %}
  30.             {{ ((write_byte | int) / (time_since | int) / 1000000) | round (2) }}
  31.           {% endif %}
  32.         unit_of_measurement: 'MB/s'
  33.       - name: "Titan D Drive Read Bytes"
  34.         value_template: >-
  35.           {% set read_byte = value_json.diskio[1].read_bytes if value_json.diskio|length else none %}
  36.           {% set time_since = value_json.diskio[1].time_since_update if value_json.diskio|length else none %}
  37.           {% if (read_byte != None ) and (time_since != None ) %}
  38.             {{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
  39.           {% endif %}
  40.         unit_of_measurement: 'MB/s'
  41.       - name: "Titan D Drive Write Bytes"
  42.         value_template: >-
  43.           {% set write_byte = value_json.diskio[1].write_bytes if value_json.diskio|length else none %}
  44.           {% set time_since = value_json.diskio[1].time_since_update if value_json.diskio|length else none %}
  45.           {% if (write_byte != None ) and (time_since != None ) %}
  46.             {{ ((write_byte | int) / (time_since | int) / 1000000) | round (2) }}
  47.           {% endif %}
  48.         unit_of_measurement: 'MB/s'
  49.       - name: "Titan E Drive Read Bytes"
  50.         value_template: >-
  51.           {% set read_byte = value_json.diskio[2].read_bytes if value_json.diskio|length else none %}
  52.           {% set time_since = value_json.diskio[2].time_since_update if value_json.diskio|length else none %}
  53.           {% if (read_byte != None ) and (time_since != None ) %}
  54.             {{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
  55.           {% endif %}
  56.         unit_of_measurement: 'MB/s'
  57.       - name: "Titan E Drive Write Bytes"
  58.         value_template: >-
  59.           {% set write_byte = value_json.diskio[2].write_bytes if value_json.diskio|length else none %}
  60.           {% set time_since = value_json.diskio[2].time_since_update if value_json.diskio|length else none %}
  61.           {% if (write_byte != None ) and (time_since != None ) %}
  62.             {{ ((write_byte | int) / (time_since | int) / 1000000) | round (2) }}
  63.           {% endif %}
  64.         unit_of_measurement: 'MB/s'
  65.       - name: "Titan C Drive Used"
  66.         value_template: '{{ value_json.fs.0.percent }}'
  67.         unit_of_measurement: "%"
  68.       - name: "Titan D Drive Used"
  69.         value_template: '{{ value_json.fs.1.percent }}'
  70.         unit_of_measurement: "%"
  71.       - name: "Titan E Drive Used"
  72.         value_template: '{{ value_json.fs.2.percent }}'
  73.         unit_of_measurement: "%"
  74.       - name: "Titan RAM"
  75.         value_template: '{{ value_json.mem.percent | round }}'
  76.         unit_of_measurement: "%"
  77.       - name: "Titan RAM Used"
  78.         value_template: '{{ (((value_json.mem.used / 1024) / 1024) / 1024) | round (1) }}'
  79.         unit_of_measurement: "GB"
  80.       - name: "Titan RAM Free"
  81.         value_template: '{{ (((value_json.mem.free / 1024) / 1024) / 1024) | round (1) }}'
  82.         unit_of_measurement: "GB"
  83.       - name: "Titan Pagefile"
  84.         value_template: '{{ value_json.memswap.percent | round }}'
  85.         unit_of_measurement: "%"
  86.       - name: "Titan Download Speed"
  87.         value_template: >-
  88.           {% set receive = value_json.network[0].rx if value_json.network|length else none %}
  89.           {% set time_since = value_json.network[0].time_since_update if value_json.network|length else none %}
  90.           {% if (receive != None ) and (time_since != None ) %}
  91.             {{ ((receive | int) / (time_since | int) / 1000000) | round (2) }}
  92.           {% endif %}
  93.         unit_of_measurement: 'MB/s'
  94.       - name: "Titan Upload Speed"
  95.         value_template: >-
  96.           {% set transmit = value_json.network[0].tx if value_json.network|length else none %}
  97.           {% set time_since = value_json.network[0].time_since_update if value_json.network|length else none %}
  98.           {% if (transmit != None ) and (time_since != None ) %}
  99.             {{ ((transmit | int) / (time_since | int) / 1000000) | round (2) }}
  100.           {% endif %}
  101.         unit_of_measurement: 'MB/s'
  102.       - name: "Titan Total Speed"
  103.         value_template: >-
  104.           {% set total = value_json.network[0].cx if value_json.network|length else none %}
  105.           {% set time_since = value_json.network[0].time_since_update if value_json.network|length else none %}
  106.           {% if (total != None ) and (time_since != None ) %}
  107.             {{ ((total | int) / (time_since | int) / 1000000) | round (2) }}
  108.           {% endif %}
  109.         unit_of_measurement: 'MB/s'
  110.       - name: "Titan Process Total"
  111.         value_template: '{{ value_json.processcount.total }}'
  112.       - name: "Titan Process Running"
  113.         value_template: '{{ value_json.processcount.running }}'
  114.       - name: "Titan Process Sleeping"
  115.         value_template: '{{ value_json.processcount.sleeping }}'
  116.       - name: "Titan Process Threads"
  117.         value_template: '{{ value_json.processcount.thread }}'
  118.       - name: "Process 0 CPU Percent"
  119.         value_template: "{{ value_json.processlist.0.cpu_percent | round(1) }}"
  120.         unit_of_measurement: "%"
  121.       - name: "Process 0 VIRT"
  122.         value_template: "{{ ((value_json.processlist.0.memory_info[0] / 1024) / 1024) | round(1) }}"
  123.         unit_of_measurement: "MB"
  124.       - name: "Process 0 RES"
  125.         value_template: "{{ ((value_json.processlist.0.memory_info[1] / 1024) / 1024) | round(1) }}"
  126.         unit_of_measurement: "MB"
  127.       - name: "Process 0 EXE"
  128.         value_template: >-
  129.           {% set EXE = value_json.processlist[0].cmdline | regex_findall('([^\\\\]+\\.exe|[\w\.]+\.py|[\w\.]+\.cmd|[\w\.]+\.bat)', False) | join(', ') %}
  130.           {% if not EXE == "" %}
  131.             {{ EXE }}
  132.           {% else %}
  133.             {{ value_json.processlist[0].name }}
  134.           {% endif %}
  135.       - name: "Process 1 CPU Percent"
  136.         value_template: "{{ value_json.processlist.1.cpu_percent | round(1) }}"
  137.         unit_of_measurement: "%"
  138.       - name: "Process 1 VIRT"
  139.         value_template: "{{ ((value_json.processlist.1.memory_info[0] / 1024) / 1024) | round(1) }}"
  140.         unit_of_measurement: "MB"
  141.       - name: "Process 1 RES"
  142.         value_template: "{{ ((value_json.processlist.1.memory_info[1] / 1024) / 1024) | round(1) }}"
  143.         unit_of_measurement: "MB"
  144.       - name: "Process 1 EXE"
  145.         value_template: >-
  146.           {% set EXE = value_json.processlist[1].cmdline | regex_findall('([^\\\\]+\\.exe|[\w\.]+\.py|[\w\.]+\.cmd|[\w\.]+\.bat)', False) | join(', ') %}
  147.           {% if not EXE == "" %}
  148.             {{ EXE }}
  149.           {% else %}
  150.             {{ value_json.processlist[1].name }}
  151.           {% endif %}
  152.       - name: "Process 2 CPU Percent"
  153.         value_template: "{{ value_json.processlist.2.cpu_percent | round(1) }}"
  154.         unit_of_measurement: "%"
  155.       - name: "Process 2 VIRT"
  156.         value_template: "{{ ((value_json.processlist.2.memory_info[0] / 1024) / 1024) | round(1) }}"
  157.         unit_of_measurement: "MB"
  158.       - name: "Process 2 RES"
  159.         value_template: "{{ ((value_json.processlist.2.memory_info[1] / 1024) / 1024) | round(1) }}"
  160.         unit_of_measurement: "MB"
  161.       - name: "Process 2 EXE"
  162.         value_template: >-
  163.           {% set EXE = value_json.processlist[2].cmdline | regex_findall('([^\\\\]+\\.exe|[\w\.]+\.py|[\w\.]+\.cmd|[\w\.]+\.bat)', False) | join(', ') %}
  164.           {% if not EXE == "" %}
  165.             {{ EXE }}
  166.           {% else %}
  167.             {{ value_json.processlist[2].name }}
  168.           {% endif %}
  169.       - name: "Process 3 CPU Percent"
  170.         value_template: "{{ value_json.processlist.3.cpu_percent | round(1) }}"
  171.         unit_of_measurement: "%"
  172.       - name: "Process 3 VIRT"
  173.         value_template: "{{ ((value_json.processlist.3.memory_info[0] / 1024) / 1024) | round(1) }}"
  174.         unit_of_measurement: "MB"
  175.       - name: "Process 3 RES"
  176.         value_template: "{{ ((value_json.processlist.3.memory_info[1] / 1024) / 1024) | round(1) }}"
  177.         unit_of_measurement: "MB"
  178.       - name: "Process 3 EXE"
  179.         value_template: >-
  180.           {% set EXE = value_json.processlist[3].cmdline | regex_findall('([^\\\\]+\\.exe|[\w\.]+\.py|[\w\.]+\.cmd|[\w\.]+\.bat)', False) | join(', ') %}
  181.           {% if not EXE == "" %}
  182.             {{ EXE }}
  183.           {% else %}
  184.             {{ value_json.processlist[3].name }}
  185.           {% endif %}
  186.       - name: "Process 4 CPU Percent"
  187.         value_template: "{{ value_json.processlist.4.cpu_percent | round(1) }}"
  188.         unit_of_measurement: "%"
  189.       - name: "Process 4 VIRT"
  190.         value_template: "{{ ((value_json.processlist.4.memory_info[0] / 1024) / 1024) | round(1) }}"
  191.         unit_of_measurement: "MB"
  192.       - name: "Process 4 RES"
  193.         value_template: "{{ ((value_json.processlist.4.memory_info[1] / 1024) / 1024) | round(1) }}"
  194.         unit_of_measurement: "MB"
  195.       - name: "Process 4 EXE"
  196.         value_template: >-
  197.           {% set EXE = value_json.processlist[4].cmdline | regex_findall('([^\\\\]+\\.exe|[\w\.]+\.py|[\w\.]+\.cmd|[\w\.]+\.bat)', False) | join(', ') %}
  198.           {% if not EXE == "" %}
  199.             {{ EXE }}
  200.           {% else %}
  201.             {{ value_json.processlist[4].name }}
  202.           {% endif %}
  203.       - name: "Titan Uptime"
  204.         value_template: '{{ value_json.uptime | regex_replace(find="[\"]", replace="") | regex_replace(find="(?<=( (\d{1})|(\d{2})):\d{2}):\d{2}", replace=" hours") }}'
  205.    verify_ssl: false
  206.    timeout: 30
  207.    scan_interval: 6
  208.  
Advertisement
Add Comment
Please, Sign In to add comment