File indexing completed on 2024-05-12 05:48:36

0001 /*
0002     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "authenticationAnalyzer.h"
0008 
0009 AuthenticationAnalyzer::AuthenticationAnalyzer(LogMode *logMode)
0010     : SyslogAnalyzer(logMode)
0011 {
0012 }
0013 
0014 LogLine *AuthenticationAnalyzer::parseMessage(const QString &logLine, const LogFile &originalLogFile)
0015 {
0016     LogLine *syslogLine = SyslogAnalyzer::parseMessage(logLine, originalLogFile);
0017 
0018     const QString message = syslogLine->logItems().at(syslogLine->logItems().count() - 1);
0019 
0020     if (hasErrorKeywords(message)) {
0021         syslogLine->setLogLevel(Globals::instance().errorLogLevel());
0022     } else if (hasWarningKeywords(message)) {
0023         syslogLine->setLogLevel(Globals::instance().warningLogLevel());
0024     }
0025 
0026     return syslogLine;
0027 }
0028 
0029 bool AuthenticationAnalyzer::hasWarningKeywords(const QString &message)
0030 {
0031     auto *configuration = mLogMode->logModeConfiguration<AuthenticationConfiguration *>();
0032     return hasKeywords(message, configuration->warningKeywords());
0033 }
0034 
0035 bool AuthenticationAnalyzer::hasErrorKeywords(const QString &message)
0036 {
0037     auto *configuration = mLogMode->logModeConfiguration<AuthenticationConfiguration *>();
0038     return hasKeywords(message, configuration->errorKeywords());
0039 }
0040 
0041 bool AuthenticationAnalyzer::hasKeywords(const QString &message, const QStringList &keywords)
0042 {
0043     for (const QString &keyword : keywords) {
0044         if (message.contains(keyword, Qt::CaseInsensitive)) {
0045             return true;
0046         }
0047     }
0048 
0049     return false;
0050 }
0051 
0052 #include "moc_authenticationAnalyzer.cpp"