An open API service indexing awesome lists of open source software.

https://github.com/dhaoloth/terminal_monitoring

This is the first stable release of the Terminal Monitoring Script. Features: - Monitors active terminal sessions on multiple servers. - Tracks session durations and stores data in a SQLite database. - Supports customizable data export (CSV, API, etc.).
https://github.com/dhaoloth/terminal_monitoring

api-integration automation csv-export customizable data-export logging open-source python-script server-monitoring session-duration session-tracking sqlite-database system-administration

Last synced: 11 months ago
JSON representation

This is the first stable release of the Terminal Monitoring Script. Features: - Monitors active terminal sessions on multiple servers. - Tracks session durations and stores data in a SQLite database. - Supports customizable data export (CSV, API, etc.).

Awesome Lists containing this project

README

          

```markdown
# Terminal Session Monitoring Script

This script monitors active terminal sessions on specified servers, tracks session durations, and stores the data in a SQLite database. It is designed to be easily customizable for various use cases, such as generating reports, exporting data to external systems, or integrating with APIs.

## Features

- **Active Session Monitoring**: Tracks active terminal sessions on multiple servers.
- **Session Duration Tracking**: Calculates the duration of each session and updates the total time for each user.
- **Database Storage**: Stores session data in a SQLite database for easy querying and analysis.
- **Customizable Export**: Provides examples for exporting data to CSV, external APIs, or other formats.

## Requirements

- Python 3.6 or higher
- SQLite3 (included with Python)
- `subprocess` module (included with Python)
- `logging` module (included with Python)

## Installation

1. Clone the repository:
```bash
git clone https://github.com/yourusername/terminal-monitoring.git
cd terminal-monitoring
```

2. Install dependencies (if any):
```bash
pip install -r requirements.txt
```

3. Configure the script:
- Update the `SERVERS` list in the script with your server names.
- Adjust the `CHECK_INTERVAL` (in seconds) to control how often the script checks for active sessions.

## Usage

Run the script:
```bash
python terminal_monitoring.py
```

The script will:
- Monitor active sessions on the specified servers.
- Store session data in a SQLite database (`sessions.db`).
- Log activities to `script.log`.

## Customization

### Exporting Data

You can customize the script to export data in various formats. Here are some examples:

#### 1. Export to CSV
To export user session data to a CSV file, add the following code to the `main` function:
```python
with open("report.csv", "w") as file:
file.write("Username,TotalMinutes\n")
with sqlite3.connect(DB_PATH) as conn:
cursor = conn.cursor()
cursor.execute("SELECT Username, TotalMinutes FROM Users;")
for row in cursor.fetchall():
file.write(f"{row[0]},{row[1]}\n")
```

#### 2. Export to an External API
To send data to an external API, use the `requests` library:
```python
import requests

def export_to_api(data):
url = "https://yourapi.com/endpoint"
response = requests.post(url, json=data)
if response.status_code == 200:
logging.info("Data successfully exported to the API.")
else:
logging.error(f"Failed to export data to the API: {response.status_code}")

# Example usage in the main function:
with sqlite3.connect(DB_PATH) as conn:
cursor = conn.cursor()
cursor.execute("SELECT Username, TotalMinutes FROM Users;")
data = [{"username": row[0], "total_minutes": row[1]} for row in cursor.fetchall()]
export_to_api(data)
```

#### 3. Generate a PDF Report
To generate a PDF report, use a library like `ReportLab`:
```python
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

def generate_pdf_report():
pdf = canvas.Canvas("report.pdf", pagesize=letter)
pdf.drawString(100, 750, "User Session Report")
y = 700
with sqlite3.connect(DB_PATH) as conn:
cursor = conn.cursor()
cursor.execute("SELECT Username, TotalMinutes FROM Users;")
for row in cursor.fetchall():
pdf.drawString(100, y, f"User: {row[0]}, Total Minutes: {row[1]}")
y -= 20
pdf.save()

# Example usage in the main function:
generate_pdf_report()
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.