From patchwork Fri Apr 5 03:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaev Ruslan X-Patchwork-Id: 1920032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=WZxyWeGN; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Us7bKaFm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V9kvp0CBqz1yZM for ; Fri, 5 Apr 2024 14:47:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Date:From:To: Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=97tMy0IHEJqsvPMfCDw1WHAFRlkEeD3JJtP0RNq9yNw=; b=WZxyWeGNMJHP5k 4iBqyZZVhYAcAuod3vATcju/V3ejFBIFAd7OBrJ4uUdIiwXa81mJI3UMV6TfPe6ipGJbDwPwEz57R cY+LCdqyufSPv68OrqSvCnBkUUfpoH2durHUdU/7TWHFDJTNzL24SIu/+zuemL0AAMQaeO5JzPl3V INltJ2b4oN2AHT5S6yowHqdEInvtC1SFHLG/daM0vW/4cyiYVj6jt+5jf1SYIqKEWFamG/mbGqe/g ngKf8QWbIsdQY5k2hIlGnBlXO3OdDReMnCgA8LkbxD40UQRhZZGUdhY2fbPkoYYO1GOQRsyYN0taK Dv5b9TuaTyE7znXanDAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsaWt-000000054kI-1OTC; Fri, 05 Apr 2024 03:46:15 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsaWr-000000054jt-0DJu for openwrt-devel@lists.openwrt.org; Fri, 05 Apr 2024 03:46:14 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-516d3776334so440739e87.1 for ; Thu, 04 Apr 2024 20:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712288770; x=1712893570; darn=lists.openwrt.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=hlgvoSQ4MVTsHtV42ClhcOaRjyXqfkctUI8tvRrw9sc=; b=Us7bKaFm3QQbHZ/l8zSaDn1iuOn4EYCS7N8OVbp5AsfhPKoUmNgCFwK8lb3YWd7bUq yYdo5wZcgTSHfy35wTiTG/wBc3kYjjZj0uom2aoPBNG6wHTpi5hCBdx6gXRg0c2DSnj0 W60j/PAuO8BOIts16wM0+3j8ql1dlNUfp41WG3E2u1CtWXY7dlV7fgj5KER5kx9C9B/Z tUYrCRI9zfVgNcv93sgcHRacDLd5lu5jYvTF7W3uTjkz10rzn7fCwjEeAk4mRk+w/gTd VtVun+C951V/+32s7MDe3qrFthI+z/8ddpNm3RlviqlGrYivHYQIjwnwBAn8LNf2BVYe S58A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712288770; x=1712893570; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hlgvoSQ4MVTsHtV42ClhcOaRjyXqfkctUI8tvRrw9sc=; b=hEIYLuAzusreBBH2L1j2CM9CuPLnugSssy8BMAmFmTC5k4DZl0Gn3/AIZBG22jr2Oz ciw/L6BkoRJn4+WCl8xGrVv4mGX61ho+XSvB2WMqP67OBcyh1dKdViOBDFbRFSChhqNZ A8U655eahsS9m2uw6rhfDPjGGHfayiUhyFugF5mBzIEneAgAGtAg2BSIgNUvaIttS9Tp Shpky4ExAOkwyRleKEV+f2qmxkVsisRWEo5z1UI50UWhhPFn47KkOvjBm7CxRo11izVK wQprVwH543G/bgEM89zhGy9JSoFNAk6SkELvp75OKpRkjgvyL8BGqYzYa0sZ5mr9QBkb OXCw== X-Gm-Message-State: AOJu0YyZJ9FFxVvXeCX0FYUIBazHRQuyaxD09u2to3ZU5Hzgxo1zoWiP g0ZnQ49omNhkRRUw4313FOBeglENQKLGS0nJDpN2ueYB40AzCy8xD9lv1AU5GIkmNw== X-Google-Smtp-Source: AGHT+IFnL8qcmJ771J9n80Vu0kgNlq285w2RHlC/w0TnXvDEVmENxhf89skLMvFLEVKiVSHu0SvKmQ== X-Received: by 2002:ac2:4db2:0:b0:515:d31f:ce2b with SMTP id h18-20020ac24db2000000b00515d31fce2bmr172052lfe.15.1712288770119; Thu, 04 Apr 2024 20:46:10 -0700 (PDT) Received: from localhost (nat-inorg.chem.msu.ru. [93.180.12.29]) by smtp.gmail.com with ESMTPSA id n29-20020ac2491d000000b00515a9f59cdbsm77766lfi.25.2024.04.04.20.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 20:46:09 -0700 (PDT) Message-ID: <814cd0aa4dc5d19a4548e186880549af.legale.legale@gmail.com> To: openwrt-devel@lists.openwrt.org, John Crispin From: Isaev Ruslan Date: Fri, 5 Apr 2024 06:36:38 +0300 Subject: [PATCH v2] add filter logread messages by priority rsyslog related X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_204613_185211_3AB702DF X-CRM114-Status: GOOD ( 11.95 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This adds an ability to filter log messages priority: -v handle only messages with given log level (0-7), repeatable -V ignore messages with given log level (0-7), repeatable This function is primarily needed to limit the messages sent to rsyslog from the system log (performed using logread) by message priority levels, for example, by sending messages only up to the LOG_ER [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:12d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [legale.legale(at)gmail.com] X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This adds an ability to filter log messages priority: -v handle only messages with given log level (0-7), repeatable -V ignore messages with given log level (0-7), repeatable This function is primarily needed to limit the messages sent to rsyslog from the system log (performed using logread) by message priority levels, for example, by sending messages only up to the LOG_ERR or LOG_WARNING levels. Signed-off-by: Isaev Ruslan --- log/logread.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/log/logread.c b/log/logread.c index f48dd4b..87ec873 100644 --- a/log/logread.c +++ b/log/logread.c @@ -66,6 +66,8 @@ static int log_type = LOG_STDOUT; static int log_size, log_udp, log_follow, log_trailer_null = 0; static int log_timestamp; static int logd_conn_tries = LOGD_CONNECT_RETRY; +static int loglevel_include; +static int loglevel_exclude; static int facility_include; static int facility_exclude; @@ -79,6 +81,16 @@ static int check_facility_filter(int f) return 1; } +/* check for loglevel filter; return 0 if message shall be dropped */ +static int check_loglevel_filter(int f) +{ + if (loglevel_include) + return !!(loglevel_include & (1 << f)); + if (loglevel_exclude) + return !(loglevel_exclude & (1 << f)); + return 1; +} + static const char* getcodetext(int value, CODE *codetable) { CODE *i; @@ -156,6 +168,9 @@ static int log_notify(struct blob_attr *msg) if (!check_facility_filter(LOG_FAC(p))) return 0; + if (!check_loglevel_filter(LOG_PRI(p))) + return 0; + m = blobmsg_get_string(tb[LOG_MSG]); if (regexp_pattern && regexec(®exp_preg, m, 0, NULL, 0) == REG_NOMATCH) @@ -233,6 +248,8 @@ static int usage(const char *prog) " -p PID file\n" " -h Add hostname to the message\n" " -P Prefix custom text to streamed messages\n" + " -v handle only messages with given log level (0-7), repeatable\n" + " -V ignore messages with given log level (0-7), repeatable\n" " -z handle only messages with given facility (0-23), repeatable\n" " -Z ignore messages with given facility (0-23), repeatable\n" " -f Follow log messages\n" @@ -313,7 +330,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - while ((ch = getopt(argc, argv, "u0fcs:l:z:Z:r:F:p:S:P:h:e:t")) != -1) { + while ((ch = getopt(argc, argv, "u0fcs:l:v:V:z:Z:r:F:p:S:P:h:e:t")) != -1) { switch (ch) { case 'u': log_udp = 1; @@ -343,6 +360,14 @@ int main(int argc, char **argv) case 'l': lines = atoi(optarg); break; + case 'v': + id = strtoul(optarg, NULL, 0) & 0x1f; + loglevel_include |= (1 << id); + break; + case 'V': + id = strtoul(optarg, NULL, 0) & 0x1f; + loglevel_exclude |= (1 << id); + break; case 'z': id = strtoul(optarg, NULL, 0) & 0x1f; facility_include |= (1 << id);