侧边栏壁纸
博主头像
Wood Chen博主等级

独唱独酬,独行独坐还独卧

  • 累计撰写 207 篇文章
  • 累计创建 126 个标签
  • 累计收到 6 条评论

目 录CONTENT

文章目录

PandoraNext项目,自动监控余额并发到飞书webhook(或其他)

wood
2023-12-15 / 0 评论 / 0 点赞 / 59 阅读 / 2963 字
PandoraNext项目地址:https://github.com/pandora-next/deploy
spug项目地址:https://github.com/openspug/spug
飞书:https://www.feishu.cn/

1. 通过spug创建一个任务计划

2. 添加shell命令

命令如下

其他的webhook地址可能有自己的要求,根据需要微调

#!/bin/bash

# 获取原始数据
original_data=$(curl -X GET "https://dash.pandoranext.com/api/UMSgTxxxpHWqU/usage")

# 提取所需字段
current=$(echo "$original_data" | jq -r '.current')
total=$(echo "$original_data" | jq -r '.total')
ip=$(echo "$original_data" | jq -r '.ip')
license_id=$(echo "$original_data" | jq -r '.license_id')
ttl_seconds=$(echo "$original_data" | jq -r '.ttl')

# 将秒数转换为小时、分钟、秒
hours=$((ttl_seconds / 3600))
minutes=$(( (ttl_seconds % 3600) / 60 ))
seconds=$((ttl_seconds % 60))

# 格式化重置时间
reset_time="${hours}H${minutes}M${seconds}S"

# 构建新的消息体,使用 \n 进行换行
formatted_message='{"msg_type":"text","content":{"text":"Pandora余额 \n用量:'"$current/$total"'\n许可IP:'"$ip"'\nlicense_id:'"$license_id"'\n重置时间:'"$reset_time"'"}}'

# 使用 curl 发送请求
curl -X POST -H "Content-Type: application/json" -d "$formatted_message" https://open.feishu.cn/open-apis/bot/v2/hook/e919axxxxxxec1

# 输出新的消息体
echo "新的消息体:$formatted_message"

3. 选择执行对象

需要是安装PandoraNext项目的机器

4. 设置运行规则

0 9-21 * * 1-5
如果觉得太频繁,可以改成2个小时一次
0 9-21/2 * * 1-5

5. 执行测试,并激活任务

6. 成果展示

PS:如果执行提示 jq: command not found

需要安装jq(jq 是一个用于处理 JSON 数据的命令行工具)

在 Ubuntu 或 Debian 上安装 jq:

sudo apt-get update
sudo apt-get install jq

在 CentOS 或 RHEL 上安装 jq:

sudo yum install jq

在 macOS 上安装 jq(使用 Homebrew):

brew install jq

如果安装jq报错

[root@1panel ~]# sudo yum install jq
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.ustc.edu.cn
没有可用软件包 jq。
错误:无须任何处理

执行下面3条命令

sudo yum update
sudo yum install epel-release
sudo yum install jq
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区