小编pea*_*eak的帖子

美化流日志中的 json

我正在尝试美化 aws 日志流

日志格式:

2022-09-07T17:14:35.987000+00:00 2022/09/07/[$LATEST]58f517bs4ebcsae033sd953bs734224 {"cold_start":true,"function_memory_size":512,"function_request_id":"a2cfdd5d-4b0b-4cfa-97c2-4af9ba6a1056","level":"ERROR","message":"Unexpected","sampling_rate":1,"timestamp":"2022-09-07T17:14:35.987Z","xray_trace_id":"1-6318d178-0e96c13a1399a74b4f353edd","extra":"{\"error\":\"AccessDeniedException: User: arn:aws:sts::\",\"stack\":\"AccessDeniedException: User: arn:aws:sts::\"}"}
Run Code Online (Sandbox Code Playgroud)

我想将其更改为

2022-09-07T17:14:35.987000+00:00 2022/09/07/[$LATEST]58f51004277b4ebcae033d953b734224 {
  "cold_start": true,
  "function_memory_size": 512,
  "function_request_id": "a2cfdd5d-4b0b-4cfa-97c2-4af9ba6a1056",
  "level": "ERROR",
  "message": "Unexpected",
  "sampling_rate": 1,
  "timestamp": "2022-09-07T17:14:35.987Z",
  "xray_trace_id": "1-6318d178-0e96c13a1399a74b4f353edd",
  "extra": '{"error":"AccessDeniedException: User: arn:aws:sts::","stack":"AccessDeniedException: User: arn:aws:sts::"}',
}
Run Code Online (Sandbox Code Playgroud)

我试过这个

aws logs tail /aws/lambda/lambda-name | sed -u -e "s/\({.*}\)/$(echo \'\\1\' | jq)/"
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误

parse error: Invalid numeric literal at line 2, column 0
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

bash logging json sed jq

1
推荐指数
1
解决办法
199
查看次数

使用jq提取数据时如何删除空值?

您好,我有一个 kubernets 审核日志文件,扩展名为 . 日志文件包含 json 记录数据。我想解析过滤器中的记录。

以下是文件中的示例记录

{"kind":"Event","apiVersion":"audit.k8s.io/v1","level":"Metadata","auditID":"60cc3bf1-a04e-4db3-a343-98aaaea8c4a5","stage":"ResponseComplete","requestURI":"/api/v1/serviceaccounts?limit=500\u0026resourceVersion=0","verb":"list","user":{"username":"system:apiserver","uid":"7cded9c8-a35d-4e66-adf1-162ce37d5868","groups":["system:masters"]},"sourceIPs":["::1"],"userAgent":"kube-apiserver/v1.24.12 (linux/amd64) kubernetes/ef70d26","objectRef":{"resource":"serviceaccounts","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":200},"requestReceivedTimestamp":"2023-04-06T15:10:46.594135Z","stageTimestamp":"2023-04-06T15:10:46.595016Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":""}}{"kind":"Event","apiVersion":"audit.k8s.io/v1","level":"Metadata","auditID":"1af73bde-3a0f-437d-a468-49da772d619d","stage":"ResponseComplete","requestURI":"/apis/batch/v1/namespaces/restricted-namespace/jobs?fieldManager=helm","verb":"create","user":{"username":"kubernetes-admin","groups":["system:masters","system:authenticated"]},"sourceIPs":["172.19.0.1"],"userAgent":"Go-http-client/2.0","objectRef":{"resource":"jobs","namespace":"restricted-namespace","name":"gateway-certgen","apiGroup":"batch","apiVersion":"v1"},"responseStatus":{"metadata":{},"code":201},"requestReceivedTimestamp":"2023-04-06T15:14:02.625749Z","stageTimestamp":"2023-04-06T15:14:02.632035Z","annotations":{"authorization.k8s.io/decision":"allow","authorization.k8s.io/reason":"","pod-security.kubernetes.io/audit-violations":"would violate PodSecurity \"restricted:v1.24\": allowPrivilegeEscalation != false (container \"certgen\" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container \"certgen\" must set securityContext.capabilities.drop=[\"ALL\"]), seccompProfile (pod or container \"certgen\" must set securityContext.seccompProfile.type to \"RuntimeDefault\" or \"Localhost\")"}}
Run Code Online (Sandbox Code Playgroud)

我想过滤掉这些记录并打印每个记录中以下字段的值。

.annotations.pod-security.kubernetes.io/audit-violations
Run Code Online (Sandbox Code Playgroud)

我正在使用这个命令,

 cat kube-apiserver-audit.log | jq '.annotations."pod-security.kubernetes.io/audit-violations"'
Run Code Online (Sandbox Code Playgroud)

但是它给出了以下输出

null
null
"would violate PodSecurity \"restricted:v1.24\": allowPrivilegeEscalation != false (container \"certgen\" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container \"certgen\" must set securityContext.capabilities.drop=[\"ALL\"]), seccompProfile (pod or container \"certgen\" must set securityContext.seccompProfile.type to …
Run Code Online (Sandbox Code Playgroud)

linux null json jq

1
推荐指数
1
解决办法
423
查看次数

PHP unserialize不断抛出相同的错误超过100次

我有一个大的2d数组,我序列化和base64_encode并扔进一个数据库.在另一个页面上,我将数组拉出来,当我输出base64_decode序列化数组时,我可以将其反射出去,它看起来确实有效.

但是,如果我尝试unserialize(base64_decode($serializedArray))它只是抛出相同的错误到几乎崩溃Firefox的点.

错误是:

警告:unserialize()[function.unserialize]:第24行的/var/www/dev/wc_paul/inc/analyzerTester.php中不再存在节点

我会包含我回应的整个序列化数组,但是上次我在这个表单上尝试过它崩溃了我的Firefox.

有谁知道为什么会发生这种情况?

php mysql serialization

0
推荐指数
1
解决办法
2461
查看次数

Kendo UI Grid条件编辑

我想为某些CatalogProductId禁用DiscountPercentageMRC/NRC/Usage列.请在网格下面找到javascript.任何帮助将不胜感激.

<h2>Kendo Grid bound to ASP.NET MVC action methods</h2>
@* The DIV where the Kendo grid will be initialized *@
<div id="grid"></div>
<script>
  $(document).ready(function () {
     $("#grid").kendoGrid({
         columns: [
         { field: "CompanyId"},
         { field: "CompanyName" },
         { field: "DiscountPercentageMRC" },
         { field: "CatalogProductId"},
         { field: "DiscountPercentageMRC" },
         { field: "DiscountPercentageNRC" },
         { field: "DiscountPercentageNRC" },
         { field: "DiscountPercentageUsage"}
         ],
        height: 400,
        editable: true, // enable editing
        pageable: true,
        sortable: true,
        filterable: true,
        toolbar: ["create", "save", "cancel","edit"], // specify toolbar commands …
Run Code Online (Sandbox Code Playgroud)

kendo-ui kendo-grid

0
推荐指数
1
解决办法
6122
查看次数

NSUserDefaults的可靠性如何?

不久前,我发现NSUserDefaults并思考:如果我能保留应用程序所需的信息NSUserDefaults,为什么还要创建数据库?这些是我的应用程序需要的变量:

  • 用户名(String类型)
  • 获得的硬币(Int16类型)
  • 雄鹿买了(Int16型)
  • 购买的物品(类型为[String])

NSUserDefaults作为使用数据库的替代方案有多适合?如果我使用NSUserDefaults而不是数据库,将所有"可购买"项目列为枚举是否合理?

nsuserdefaults ios

0
推荐指数
1
解决办法
163
查看次数

查找哈希数组的键

我有一个哈希数组,在数组中有不同的键:

csv = [{:fruit=>"apple", :number=>23},{:age=>12,:name=>"XYZ"}]
Run Code Online (Sandbox Code Playgroud)

我如何得到这样的所有键:

[:fruit,:number,:age,:name]
Run Code Online (Sandbox Code Playgroud)

我试过了

array = csv.collect {|key,value| key }
Run Code Online (Sandbox Code Playgroud)

ruby arrays key

0
推荐指数
1
解决办法
48
查看次数

如果名称存在,则更新,否则插入 - 在SQL Server中

如果我的给定文件名已经在我的数据库中,我希望在我的表中更新,否则我想插入一个新行.我尝试这个代码,但EXISTS显示的错误请给我正确的方式,因为我更新在SQL中

public void SaveData(string filename, string jsonobject)
{
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=;Integrated Security=True");
    SqlCommand cmd;
    SqlCommand cmda;

    if EXISTS("SELECT * FROM T_Pages WHERE pagename = '" + filename + "") {
        cmda = new SqlCommand("UPDATE T_Pages SET pagename='" + filename + "',pageinfo='" + jsonobject + "' WHERE pagename='" + filename + "'", con);
        cmda.ExecuteNonQuery();
    }
    else {
        cmd = new SqlCommand("insert into T_Pages (pagename,pageinfo) values('" + filename + "','" + jsonobject + "')", con);
        cmd.ExecuteNonQuery(); …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server

0
推荐指数
2
解决办法
9574
查看次数

jq:计算满足条件的嵌套对象值

json数据:

{testId: '1' studentId:{'s1':{score: 20} 's2':{score: 80}}}
{testId: '2' studentId:{'s1':{score: 60} 's2':{score: 70}}}
{testId: '3' studentId:{'s5':{score: 40} 's7':{score: 30}}}
...
Run Code Online (Sandbox Code Playgroud)

我想用JQ告诉我每个测试有多少学生达到> x的分数.

因此对于上面的输入和x = 50,输出:

{testId: '1' numStudents:1}
{testId: '2' numStudents:2}
{testId: '3' numStudents:0}
Run Code Online (Sandbox Code Playgroud)

我能够生成一份列表,列出了每次考试成绩> 50的学生

{testId, studentId: .studentId[]?} | select(.studentId.score>50)
Run Code Online (Sandbox Code Playgroud)

此命令创建一个对象列表,其中每个对象包含testId,studentId和score,其中所有分数都大于50.但是我不知道如何将这些结果重新组合到我想要的输出中.

command-line json count jq

0
推荐指数
1
解决办法
1059
查看次数

使用 JQ 从一组字符串中获取唯一字符串

我有从 jq 中提取的字符串,我只想从中获取唯一值。

"a-b-c-v001"
"a-b-c-v002"
"a-b-c-v001"
"a-b-c-v003"
"a-b-c-v002"  
Run Code Online (Sandbox Code Playgroud)

我只需要 3 个结果,独一无二

"a-b-c-v001"
"a-b-c-v002"
"a-b-c-v003"  
Run Code Online (Sandbox Code Playgroud)

我试过 unique & sort 没有用 - https://jqplay.org/s/xjND6Iv60T

json unique stream jq

0
推荐指数
1
解决办法
2889
查看次数

使用jq使用空格导出环境变量

所以,我正在尝试导出一个来自api的环境变量,它返回json值.想使用jq只做一个衬垫,但如果值有空格我不能让它工作

尝试不包围引号中的值

/app/src $ $(echo '{"params":[{ "Name":"KEY","Value":"value with space"}]}' | jq
 -r '.params[] | "export " + .Name + "=" + .Value')
/app/src $ printenv KEY
value
/app/src $ 
Run Code Online (Sandbox Code Playgroud)

接下来,我尝试将值包装在引号中

/app/src $ $(echo '{"params":[{ "Name":"KEY","Value":"value with space"}]}' | jq
 -r '.params[] | "export " + .Name + "=\"" + .Value + "\""')
sh: export: space": bad variable name
/app/src $ 
Run Code Online (Sandbox Code Playgroud)

bash environment-variables jq

0
推荐指数
1
解决办法
846
查看次数