Welcome to the Monitoring Program! This is a powerful and flexible tool designed to monitor databases by executing dynamic queries and sending the results via email. It supports multiple database types, including PostgreSQL, Microsoft SQL Server (MSSQL), Oracle, and MariaDB/MySQL. The program reads queries from a configuration file, executes them, and sends the results as an HTML table in an email.
- Dynamic Query Execution: Execute SQL queries stored in a configuration file.
- Multiple Database Support: Works with PostgreSQL, MSSQL, and Oracle.
- Email Notifications: Send query results as an HTML table in an email.
- Flexible Configuration: Configure database connections, SMTP settings, and queries in a single file (
data.config). - CSV Attachment: Attach query results as a CSV file in the email.
Before running the program, ensure you have the following installed:
- .NET Core: Download and install the .NET Core 8 (version 8.0 or later).
- Database: Access to a supported database (PostgreSQL, MSSQL, Oracle, or MariaDB/MySQL).
- SMTP Server: Access to an SMTP server for sending emails (e.g., Gmail, Outlook, or your organization's SMTP server).
Clone this repository to your local machine:
git clone https://github.com/marchelgunawan/monitoring-program.git
cd monitoring-programInstall the required .NET packages based on your database type:
For PostgreSQL:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQLFor MSSQL:
dotnet add package Microsoft.EntityFrameworkCore.SqlServerFor Oracle:
dotnet add package Oracle.EntityFrameworkCoreCore Packages (Required for All Databases):
dotnet add package Microsoft.Extensions.DependencyInjection
dotnet add package Microsoft.Extensions.Configuration.Json
dotnet add package ConsoleTables
dotnet add package Microsoft.EntityFrameworkCoreCreate a data.config file in the project root directory. This file contains all the configuration settings for the program. Here’s an example:
# Database Config
# dbType = posgre: psql, mssql : sql, oracle: oracle, mariaDB: mariaDB
dbType=psql
dbIP=127.0.0.1
dbPort=5432
dbDatabase=Test
dbUser=Test
dbPass=P@ssw0rd
# SMTP Config
emailFrom=test@gmail.com
emailTo=recipient@example.com
emailCc=cc@example.com
emailSubject=Monitoring(yyyy-mm-dd_now)
emailBody=Attached Monitoring
smtpIP=smtp.gmail.com
smtpPort=587
smtpAuth=true
smtpTLS=true
smtpUser=test@gmail.com
smtpPass=your-app-specific-password
# Query Config
queryData=Table_1,Table_2
query.Table_1=SELECT * FROM Table_1
query.Table_2=SELECT * FROM Table_2If you're using Gmail, generate an app-specific password:
-
Go to your Google Account Security.
-
Enable 2-Step Verification.
-
Generate an app-specific password and use it for smtpPass.
Run the following command to build the project:
dotnet buildExecute the program using the following command:
dotnet run-
Read Configuration: The program reads the data.config file to get database and SMTP settings.
-
Execute Queries: It executes the queries specified in the queryData section.
-
Generate Results: The query results are formatted as an HTML table and attached as a CSV file.
-
Send Email: The results are sent via email using the configured SMTP settings.
Id,Name,Status
1,John Doe,Active
2,Jane Smith,InactiveAdd more queries to the data.config file under the queryData and query sections.
Modify the emailBody in the data.config file or update the HTML generation logic in Program.cs.
Add the appropriate database provider package and update the connection string logic in ConnectionStringBuilder.cs.
