Saying "hi" to your Linux Host Information
Published: 2024-07-07 19:23:29

I wanted to share a little tool that I think you'll find to be a joy to use. Especially if you are a command-line enthusiast like myself. 

Say hello to "hi", my "Linux Host Information Reporting" tool.

I've written a little bit previously about this tool in [Introducing ‘hi’ – the Host Information tool](https://thedevopsjoint.com/2024/07/06/introducing-hi-the-host-information-tool/), so in this article, I'll just dive into what this tool does, and how to use it.

Firstly, you'll need to know where to get it. "hi" can be found on GitHub at [https://github.com/jbobbylopez/hi](https://github.com/jbobbylopez/hi).  Currently published release is a [0.1 pre-release](https://github.com/jbobbylopez/hi/releases/tag/0.1), so this tool is still in it's early development stages.  Some tests have been defined in `test_host_information.py`, and will continue to be improved in order to guide development.

Once you check-out that repository, one of the first things you'll notice is that there is no script, file, or binary called 'hi'.  The script is actually called `host_information.py`.  There are instructions in the README.txt for how to setup an alias to get the 'hi' command configured correctly.

## What is 'hi'?
"hi" is a command-line tool designed to monitor and display the status of various services running on a host. The services and their respective checks are customizable via a YAML configuration file, allowing for flexibility to suit different monitoring needs. This tool leverages the Rich library to provide visually pleasing output that includes UTF8 status icons, so it should be run in a terminal that supports the UTF8 character-set.

*Features*
* Highly customizable checks that can report on any command-line executable status.
* Verifies the running status of various services.
* Checks the last modified date of backup logs to ensure up-to-date backups.
* Monitors the connectivity status of ExpressVPN.
* Displays the local IP address and hostname of the host.
* Utilizes the Rich library for visually appealing console output with UTF8 status icons.

Here is an example of the output that 'hi' reports in the terminal:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sz0ogt58jkbpif71wcjk.png)

Using '-verbose' (subject to change), you can get some extended information reported from the 'info:' section of the check.yml configuration.

"verbose" output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fwt4nxigaoa8svhob3q1.png)

Groups can be customized in the config/groups.yml file, and only those system checks configured with the groups defined will be reported. 

Example of the groups.yml and checks.yml configuration files:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1peahyfby51oowk8rr1x.png)

## How System Checks Are Defined ##
The 'hi' checks are literally any valid bash command line that can return a non-zero value.  If the command is successful, then the check is reported as positive.  However, because the bash command includes the ability to use pipes, you have an immense amount of control around how your checks are implemented.

You can do a simple check to see if a process is running.  Lets say for example you wanted to check if the cups printing service is running on your host.  Normally the fastest way to check would be to execute a `ps -ef | grep cups` on the command-line, like so:
```
➤ ps -ef | grep cups
root      828443       1  0 Jun27 ?        00:00:00 /bin/sh /snap/cups/1058/scripts/run-cups-browsed
root      828451       1  0 Jun27 ?        00:00:00 /bin/sh /snap/cups/1058/scripts/run-cupsd
root      828648  828451  0 Jun27 ?        00:00:00 cupsd -f -s /var/snap/cups/common/etc/cups/cups-files.conf -c /var/snap/cups/common/etc/cups/cupsd.conf
root      828734  828443  0 Jun27 ?        00:00:00 /bin/sh /snap/cups/1058/scripts/run-cups-browsed
root     2458874       1  0 00:00 ?        00:00:00 /usr/sbin/cupsd -l
lp       2458875 2458874  0 00:00 ?        00:00:00 /usr/lib/cups/notifier/dbus dbus://
root     2458877       1  0 00:00 ?        00:00:00 /usr/sbin/cups-browsed
lp       2458897 2458874  0 00:00 ?        00:00:00 /usr/lib/cups/notifier/dbus dbus://
jbl      2539184 2453821  0 14:38 pts/5    00:00:00 grep --color=auto cups

```
Looks like it's running!  But I don't want to have to issue that command every time I want to know if the service is running.  And lets be honest, it's kind of noisy, and not the prettiest thing to look at if all I want to know is if the service is running.

Now with using 'hi', I can just use a similer `ps -ef | grep -E "[c]ups"` command as part of a newly defined check in `config/checks.yml`, as follows:
```
  CUPS:
    info: CUPS print service
    group: Media
    command: |
      ps -ef | grep -E "[c]ups"
```

Now when I run 'hi', I get a beautiful little indicator that tells me exactly what I want to know, amongst other information that might be important to me in general.

Output showing CUPS service indicator:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smikgl01hc1nfjnszb8i.png)

For an exmaple of a more complex check, take a look at the one defined for ExpressVPN:
```
   ExpressVPN:
     info: For general privacy and security.
     group: Security
     command: |
       expressvpn status | grep -i connected | sed "s/\\x1b\\[[0-9;]*[mGK]//g"
```
In the case of ExpressVPN, I don't just want to check if the process is running, but I'm interested in capturing a portion of the command output to be included in the 'hi' tool reporting. 

In order to leverage that output, there is a custom handler defined in `host_information.py`:
```
         elif 'expressvpn' in process.lower():    
             if re.search("Connected", output.strip()):    
                 output_messages.append(f"[✅] {process} Status: {output.strip()}")    
             else:    
                 output_messages.append(f"[❌] {process} Status: {output.strip()}")  
```

The flexibility of the 'hi' tool's bash-based checks makes this fairly easy to implement.

I have found using this tool to be an invaluable pleseant suprise, to both develop and to use.

As I mentioned in my previous article, there are many tools out there that can do some excellent reporting on host services, including running processes, CPU utilization, and file system services.  

However I've never come across such a tool that allowed me to customize the reporting, to show exactly what I wanted, and ONLY what I wanted - in a nice, organized, terminal-friendly way.  

I plan to continue development on this tool as time permits.  To keep me motivated and focused, I've added a [ROADMAP.txt](https://github.com/jbobbylopez/hi/blob/main/ROADMAP.txt) file to the repository that highlights some ideas and upcoming features that I plan to explore and implement.

I hope you find it a joy to use as much as I do.  If you want to hear more about 'hi', visit my website [The DevOps Joint](https://thedevopsjoint.com/), or connect with me on [LinkedIn](https://www.linkedin.com/in/jbobbylopez/), or [@jbobbylopez](https://x.com/jbobbylopez) on X.com.

Enjoy!