mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-07-27 10:31:38 +08:00
54 lines
1.5 KiB
Plaintext
54 lines
1.5 KiB
Plaintext
#!/usr/bin/ucode
|
|
/*
|
|
* SPDX-License-Identifier: GPL-2.0-only
|
|
*
|
|
* Copyright (C) 2021-2025 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-netdata
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import { access, popen } from 'fs';
|
|
|
|
function get_netdata_version() {
|
|
if (!access('/usr/sbin/netdata'))
|
|
return null;
|
|
|
|
const fd = popen("a=`/usr/sbin/netdata -v`&&echo $a |awk -F v '{printf $2}'");
|
|
if (fd) {
|
|
let output = trim(fd.read('all'));
|
|
fd.close();
|
|
// 方法1: 简单替换(推荐)
|
|
let version_with_v = replace(output, "netdata ", "");
|
|
// 方法2: 去掉 v 前缀
|
|
let version_clean = replace(version_with_v, "v", "");
|
|
return version_with_v; // 返回 "v2.3.2"
|
|
}
|
|
return null;
|
|
}
|
|
|
|
const methods = {
|
|
get_version: {
|
|
call: function() {
|
|
let version = get_netdata_version();
|
|
if (!version)
|
|
return { version: null, error: '无法获取 netdata 版本' };
|
|
|
|
return { version: version };
|
|
}
|
|
},
|
|
|
|
get_version_clean: {
|
|
call: function() {
|
|
let version = get_netdata_version();
|
|
if (!version)
|
|
return { version: null, error: '无法获取 netdata 版本' };
|
|
|
|
// 去掉 "v" 前缀,返回纯数字版本
|
|
let clean_version = replace(version, /^v/, "");
|
|
return { version: clean_version };
|
|
}
|
|
}
|
|
};
|
|
|
|
return { 'luci.netdata': methods };
|