This project aims to collect log data from the /var/log/auth.log
file, extract IP addresses and usernames from failed login attempts, and use API calls to get geographical data such as longitude, latitude, city, country, and more. The collected data is then saved into MariaDB and can be visualized using Grafana.
Old version collected to prometheus but I changed it to MariaDB because there were some bugs I couldn't fix :sweat_smile:
Old version still avaiable in the here.
github.com/fsnotify/fsnotify
librarygithub.com/fsnotify/fsnotify
librarygithub.com/go-sql-driver/mysql
librarygithub.com/ipdata/go
librarygithub.com/joho/godotenv
libraryContributions are welcome! If you'd like to contribute to this project, follow these steps:
git checkout -b feature/new-feature
git commit -m 'Add some feature'
git push origin feature/new-feature
Found a bug? Have a suggestion? Open an issue.
Your contributions are greatly appreciated! :rocket:
Clone the repository to your local machine:
git clone https://github.com/whosFritz/geo-mapping-ivan.git
cd geo-mapping-ivan
Install the required Go libraries:
go get github.com/fsnotify/fsnotify
go get github.com/go-sql-driver/mysql
go get github.com/ipdata/go
Create a .env file in the project directory (recommended if u contribute to this project) and add your API token :key:
Build the project:
go build
Only for the PROMETHEUS SOLUTION
Edit your prometheus.yml
// ... other configs ...
- job_name: 'geo-mapping-ivan'
metrics_path: '/metrics'
scrape_interval: 10s
static_configs:
- targets: ['localhost:9101']
// ... other configs ...
Start Prometheus
Start the application:
./geo-mapping-van
The application will monitor changes to the /var/log/auth.log file and extract data from failed login attempts. It will then record the data as Prometheus metrics. :timer_clock:
Start Grafana and set up Prometheus as a data source.
Import the provided Grafana dashboard to visualize the recorded metrics. :white_check_mark:
To ensure that the geo-mapping-ivan
application runs continuously and starts automatically upon system boot, you can create a systemd service file. Here's how to do it:
Create a new systemd service file:
sudo nano /etc/systemd/system/geo-mapping-ivan.service
Add the following content to the file:
[Unit]
Description=Geo Mapping Ivan Application
After=network.target
[Service]
ExecStart=/path/to/geo-mapping-ivan
WorkingDirectory=/path/to/geo-mapping-ivan
Restart=always
User=your_username
[Install]
WantedBy=multi-user.target
Replace /path/to/geo-mapping-ivan with the actual path to your geo-mapping-ivan executable and project directory. Also, replace your_username with your actual username.
Save the file and exit the text editor :floppy_disk:
Start and enable the service
sudo systemctl start geo-mapping-ivan
sudo systemctl enable geo-mapping-ivan
The application will now start automatically on system boot and be managed by systemd.
Monitor the service status:
sudo systemctl status geo-mapping-ivan
This command will show you the current status of the geo-mapping-ivan service. Now your application will run as a systemd service, ensuring its continuous operation and automatic start at system boot.
A sample Grafana dashboard JSON file is provided in the Grafana-Dashboard-geo-mapping-ivan.json file. You can import this dashboard into Grafana to visualize the recorded metrics. The dashboard will display information about failed login attempts, including IP addresses, usernames, geographical data, and more.
Feel free to customize the code and the Grafana dashboard to fit your needs. You can modify the Prometheus metrics, add more labels, or create new visualizations in Grafana to gain insights from the collected data.
Make sure to keep your API token secure by storing it in the .env file and adding that file to your .gitignore to prevent accidentally sharing your sensitive information.
This project is licensed under the MIT License. MIT-License