OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Profile of giff »
  • Show Posts »
  • Messages
  • Profile Info
    • Summary
    • Show Stats
    • Show Posts...
      • Messages
      • Topics
      • Attachments

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

  • Messages
  • Topics
  • Attachments

Messages - giff

Pages: [1]
1
Tutorials and FAQs / Telegraf input.exec not working
« on: April 01, 2024, 07:51:39 pm »
I am having issues trying to display logon sessions info with Telegraf. How I have my setup at work is we use Telegraf, Prometheus, Grafana. I have created a bash file that gets me the data I need in json

Code: [Select]
#!/bin/bash

# Use last -F to get detailed login information, grep for "logged" to filter relevant lines
last -F | grep logged | while read -r line; do
    # Extract username, login time, logout time, and duration
    # Adjust the awk command according to your specific output format
    username=$(echo "$line" | awk '{print $1}')
    login_time=$(echo "$line" | awk '{print $5, $6, $7, $8}')
    logout_time=$(echo "$line" | awk '{print $10, $11, $12, $13}')
 
    # Use jq to format the extracted data into JSON
    # Note: jq arguments must be passed as strings
    jq -n \
        --arg user "$username" \
        --arg login "$login_time" \
        --arg logout "$logout_time" \
        '{username: $user, login_time: $login, logout_time: $logout}'
done

Then from there my telegraf.conf file looks like this for the exec section

Code: [Select]
[[inputs.exec]]
  commands = ["/usr/local/bin/logonSessions.sh"]
  interval = "60s"
  data_format = "json"
  json_string_fields = ["username", "login_time", "logout_time"]
  name_override = "logon_sessions"
  [inputs.exec.tags]
    source = "logon_script"

We are using telegraf version 1.30. I can get other things to work without any issue but this one this seems impossible. I have ran telegraf --config --test on this and there are no issues. I have restarted telegraf. My bash script outputs correctly. I am not sure why it isn't giving me any data. I am new to all of this as my company made me the SME and I have about 4 days of experience but I need to start showing stuff on a dashboard so any help is greatly appreciated.

Pages: [1]
OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2