{"id":24585539,"url":"https://github.com/dhaoloth/terminal_monitoring","last_synced_at":"2025-03-17T18:15:38.812Z","repository":{"id":273346768,"uuid":"919399541","full_name":"dhaoloth/terminal_monitoring","owner":"dhaoloth","description":"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.).","archived":false,"fork":false,"pushed_at":"2025-01-20T10:47:23.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T11:27:15.746Z","etag":null,"topics":["api-integration","automation","csv-export","customizable","data-export","logging","open-source","python-script","server-monitoring","session-duration","session-tracking","sqlite-database","system-administration"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhaoloth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-20T10:19:20.000Z","updated_at":"2025-01-20T10:47:25.000Z","dependencies_parsed_at":"2025-01-20T11:27:19.226Z","dependency_job_id":"62bde4ce-50d7-447d-9f59-a63d12b06789","html_url":"https://github.com/dhaoloth/terminal_monitoring","commit_stats":null,"previous_names":["dhaoloth/terminal_monitoring"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhaoloth%2Fterminal_monitoring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhaoloth%2Fterminal_monitoring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhaoloth%2Fterminal_monitoring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhaoloth%2Fterminal_monitoring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhaoloth","download_url":"https://codeload.github.com/dhaoloth/terminal_monitoring/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085033,"owners_count":20395523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-integration","automation","csv-export","customizable","data-export","logging","open-source","python-script","server-monitoring","session-duration","session-tracking","sqlite-database","system-administration"],"created_at":"2025-01-24T05:13:16.055Z","updated_at":"2025-03-17T18:15:38.785Z","avatar_url":"https://github.com/dhaoloth.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"```markdown\n# Terminal Session Monitoring Script\n\nThis 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.\n\n## Features\n\n- **Active Session Monitoring**: Tracks active terminal sessions on multiple servers.\n- **Session Duration Tracking**: Calculates the duration of each session and updates the total time for each user.\n- **Database Storage**: Stores session data in a SQLite database for easy querying and analysis.\n- **Customizable Export**: Provides examples for exporting data to CSV, external APIs, or other formats.\n\n## Requirements\n\n- Python 3.6 or higher\n- SQLite3 (included with Python)\n- `subprocess` module (included with Python)\n- `logging` module (included with Python)\n\n## Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/yourusername/terminal-monitoring.git\n   cd terminal-monitoring\n   ```\n\n2. Install dependencies (if any):\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n3. Configure the script:\n   - Update the `SERVERS` list in the script with your server names.\n   - Adjust the `CHECK_INTERVAL` (in seconds) to control how often the script checks for active sessions.\n\n## Usage\n\nRun the script:\n```bash\npython terminal_monitoring.py\n```\n\nThe script will:\n- Monitor active sessions on the specified servers.\n- Store session data in a SQLite database (`sessions.db`).\n- Log activities to `script.log`.\n\n## Customization\n\n### Exporting Data\n\nYou can customize the script to export data in various formats. Here are some examples:\n\n#### 1. Export to CSV\nTo export user session data to a CSV file, add the following code to the `main` function:\n```python\nwith open(\"report.csv\", \"w\") as file:\n    file.write(\"Username,TotalMinutes\\n\")\n    with sqlite3.connect(DB_PATH) as conn:\n        cursor = conn.cursor()\n        cursor.execute(\"SELECT Username, TotalMinutes FROM Users;\")\n        for row in cursor.fetchall():\n            file.write(f\"{row[0]},{row[1]}\\n\")\n```\n\n#### 2. Export to an External API\nTo send data to an external API, use the `requests` library:\n```python\nimport requests\n\ndef export_to_api(data):\n    url = \"https://yourapi.com/endpoint\"\n    response = requests.post(url, json=data)\n    if response.status_code == 200:\n        logging.info(\"Data successfully exported to the API.\")\n    else:\n        logging.error(f\"Failed to export data to the API: {response.status_code}\")\n\n# Example usage in the main function:\nwith sqlite3.connect(DB_PATH) as conn:\n    cursor = conn.cursor()\n    cursor.execute(\"SELECT Username, TotalMinutes FROM Users;\")\n    data = [{\"username\": row[0], \"total_minutes\": row[1]} for row in cursor.fetchall()]\n    export_to_api(data)\n```\n\n#### 3. Generate a PDF Report\nTo generate a PDF report, use a library like `ReportLab`:\n```python\nfrom reportlab.lib.pagesizes import letter\nfrom reportlab.pdfgen import canvas\n\ndef generate_pdf_report():\n    pdf = canvas.Canvas(\"report.pdf\", pagesize=letter)\n    pdf.drawString(100, 750, \"User Session Report\")\n    y = 700\n    with sqlite3.connect(DB_PATH) as conn:\n        cursor = conn.cursor()\n        cursor.execute(\"SELECT Username, TotalMinutes FROM Users;\")\n        for row in cursor.fetchall():\n            pdf.drawString(100, y, f\"User: {row[0]}, Total Minutes: {row[1]}\")\n            y -= 20\n    pdf.save()\n\n# Example usage in the main function:\ngenerate_pdf_report()\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhaoloth%2Fterminal_monitoring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhaoloth%2Fterminal_monitoring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhaoloth%2Fterminal_monitoring/lists"}