The DevOps Fetch Tool (devopsfetch.sh
) is a comprehensive system information gathering script that provides insights into various aspects of a server's operation including active ports, Docker containers, Nginx configurations, user logins, and system activity logs. It is designed to run both as a standalone script and as a systemd service for continuous monitoring.
- Ports: List all active ports or information about a specific port.
- Docker: Display all Docker containers and images or details about a specific container.
- Nginx: Show all Nginx domain configurations or details for a specific domain.
- Users: List all users and their last login times or details for a specific user.
- Time Range: Display system logs for a specified time range.
- Continuous Monitoring: Continuous monitoring mode that logs updated system information every 5 minutes.
- Linux-based system (Tested on Ubuntu 20.04)
- Docker
- Nginx
- net-tools
- systemd (for setting up as a service)
-
Clone the repository:
git clone <repo> cd devopsfetch
-
Make the script executable:
sudo chmod +x devopsfetch.sh
-
Move the script to a suitable directory (optional):
sudo mv devopsfetch.sh /usr/local/bin/
-
Ensure log file is setup:
sudo touch /var/log/devopsfetch.log sudo chmod 644 /var/log/devopsfetch.log
-
Install Dependencies:
sudo apt-get update sudo apt-get install net-tools docker.io nginx
To enable continuous monitoring, you can set up devopsfetch.sh
as a systemd service.
-
Create systemd service file:
sudo nano /etc/systemd/system/devopsfetch.service
Insert the following configuration:
[Unit] Description=DevOps Fetch Service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/devopsfetch.sh -c Restart=on-failure User=root WorkingDirectory=/usr/local/bin StandardOutput=append:/var/log/devopsfetch.log StandardError=append:/var/log/devopsfetch.log [Install] WantedBy=multi-user.target
-
Reload systemd to recognize the new service:
sudo systemctl daemon-reload
-
Enable and start the service:
sudo systemctl enable devopsfetch.service sudo systemctl start devopsfetch.service
- Test listing all active ports: This will display all services currently listening on ports.
sudo /usr/local/bin/devopsfetch.sh -p
- Test a specific port: Use this to check detailed information for a known active port, such as port 80 if a web server is running.
sudo /usr/local/bin/devopsfetch.sh -p 80
- Preparation: Ensure Docker is running and has some containers for testing. If none, start a simple one:
sudo docker run -d --name test-nginx nginx
- Test listing all Docker images and containers:
sudo /usr/local/bin/devopsfetch.sh -d
- Test detailed information for a specific container: This will show detailed Docker container configuration and state.
sudo /usr/local/bin/devopsfetch.sh -d test-nginx
- Test displaying all Nginx configurations: This requires that Nginx is installed and configured with at least one site.
sudo /usr/local/bin/devopsfetch.sh -n
- Test for a specific Nginx domain configuration: Assuming a domain like
example.com
is configured, this command will display the Nginx configuration for that domain.sudo /usr/local/bin/devopsfetch.sh -n example.com
- Test listing all users and their last login times:
sudo /usr/local/bin/devopsfetch.sh -u
- Test specific user login details: Replace
username
with a real user's name to get their last login details.sudo /usr/local/bin/devopsfetch.sh -u username
- Test displaying logs for a specific time range: This could be for logs from "today" or "1 hour ago".
sudo /usr/local/bin/devopsfetch.sh -t "1 hour ago"
- Start the script in continuous monitoring mode: This mode refreshes and logs data every 5 minutes.
sudo /usr/local/bin/devopsfetch.sh -c
- Monitor the output: Let it run for a period (like 15 or 30 minutes), then check the log file to verify that it is updating.
sudo tail -f /var/log/devopsfetch.log
- Stop monitoring: Use Ctrl+C to stop monitoring the log output.
- Check the log file: To ensure all outputs are logged correctly and to understand the information being recorded.
sudo less /var/log/devopsfetch.log
-
Check service status:
sudo systemctl status devopsfetch.service
-
View service logs:
sudo tail -f /var/log/devopsfetch.log
-
Restart the service if needed:
sudo systemctl restart devopsfetch.service
The DevOps Fetch Tool is designed to provide system administrators and DevOps engineers with a powerful tool for monitoring and logging system status. By integrating it as a systemd service, it provides continuous, automated monitoring with minimal manual intervention.