Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create llm-monitor.cpp #21

Open
wants to merge 1 commit into
base: release/17.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions llm-monitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "LlamaLocal.h" // Ensure this include reflects the actual Llama Local library

// Script that uses LlamaLocal LLM to monitor FreePBX / Asterisk for Cyber Security Threats and provide report

struct LogEntry {
std::string threatType;
std::string details;
std::string timestamp;
};

// Function to read Asterisk logs
std::vector<std::string> readLogs(const std::string& logDirectory) {
std::vector<std::string> logs;
std::string line;
// Typical Asterisk log files, adjust as necessary
std::string filenames[] = {"messages", "error", "full"};

for (const auto& filename : filenames) {
std::ifstream file(logDirectory + filename);
while (getline(file, line)) {
logs.push_back(line);
}
}
return logs;
}

// Analyze logs using Llama Local
std::vector<LogEntry> analyzeLogs(const std::vector<std::string>& logs) {
LlamaLocal analyzer;
std::vector<LogEntry> results;

for (const auto& log : logs) {
LogEntry entry = analyzer.analyze(log); // Assuming 'analyze' returns a LogEntry
results.push_back(entry);
}

return results;
}

// Save results to CSV
void saveToCSV(const std::vector<LogEntry>& entries, const std::string& outfile) {
std::ofstream file(outfile);
file << "Threat Type,Details,Timestamp\n";

for (const auto& entry : entries) {
file << entry.threatType << "," << entry.details << "," << entry.timestamp << "\n";
}
}

int main() {
std::string logDirectory = "/var/log/asterisk/";
std::string csvFilename = "analysis_results.csv";

auto logs = readLogs(logDirectory);
auto analyzedResults = analyzeLogs(logs);
saveToCSV(analyzedResults, csvFilename);

return 0;
}