Get count of unique usernames from logfile - unix

I have an application log file with the name user-attribute-migration-log with contents in the following format:
[01/14/2023 09:00:42 job100.company.com uuid 158461] Error in migrating attribute for username1 in function MigrateAttribute: API Error at ...
[01/14/2023 09:02:15 job100.company.com uuid 158461] Error in migrating attribute for username2 in function MigrateAttribute: API Error at ...
[01/14/2023 10:11:02 job100.company.com uuid 158461] Error in migrating attribute for username1 in function MigrateAttribute: API Error at ...
[01/14/2023 11:34:15 job100.company.com uuid 158461] Error in migrating attribute for username1 in function MigrateAttribute: API Error at ...
[01/14/2023 13:01:58 job100.company.com uuid 158461] Error in migrating attribute for username2 in function MigrateAttribute: API Error at ...
[01/14/2023 13:02:47 job100.company.com uuid 158461] Error in migrating attribute for username3 in function MigrateAttribute: API Error at ...
Log entries can be repeated for a username. I need to get a report of the unique usernames along with the count of the number of times a user is running into this attribute migration error. I used awk utility and came up with this bash command -
awk -F "Error in migrating attribute for[ ]" '{a[$2]++} END{for(i in a){print a[i],i | "sort -nr"}}' user-attribute-migration-log
The report that I get is in this format:
3 username1 in function MigrateAttribute: API Error at ...
2 username2 in function MigrateAttribute: API Error at ...
1 username3 in function MigrateAttribute: API Error at ...
I was hoping to get a report in this format:
3 username1
2 username2
1 username3
Could you help me update the command?

Related

Xamarin Shell Raise Ambiguous Routes matched Exception - [0:] Shell: Failed to Navigate Back:

In Xamari.Forms, I use the following route declaration in AppShell.xaml.cs :
routes.Add("DSKhachHangHalf", typeof(DanhSachKHHalf));
routes.Add("chiTietHalf", typeof(ChiTietKHHalf));
routes.Add("rvatTu", typeof(vatTu));
I then navigate : DanhSachKHHalf -> ChiTietKHHalf -> rvatTu
In DanhSachKHHalf.cs i call ChiTietKHHalf with code :
await Shell.Current.GoToAsync($"chiTietHalf");
In ChiTietKHHalf.cs i call vatTu with code :
await Shell.Current.GoToAsync($"rvatTu");
or
await Shell.Current.GoToAsync($"/chiTietHalf/rvatTu");
or
await Shell.Current.GoToAsync($"DSKhachHangHalf/chiTietHalf/rvatTu");
when i go back to the page from vatTu to ChiTietKHHalf But I get this exception :
[0:] Shell: Failed to Navigate Back: System.ArgumentException:
Ambiguous routes matched for:
//D_FAULT_FlyoutItem10/IMPL_DSKhachHangHalf/DSKhachHangHalf/chiTietHalf
matches found:
//D_FAULT_FlyoutItem10/IMPL_DSKhachHangHalf/DSKhachHangHalf/chiTietHalf,//D_FAULT_FlyoutItem10/IMPL_DSKhachHangHalf/DSKhachHangHalf/chiTietHalf
Parameter name: uri

Access dictionary objects inside list using loop throwing error : list' object has no attribute 'keys or unicode' object has no attribute 'keys

For Robotframework, in given testcase code 1 and code 2 to access dictionary object. Problem is that when I use json.load to convert my json object which returns a list, returns json keys in single ' instead of double comma " object and when i don't use json.load it returns Unicode error
define library
*** Settings ***
Library OperatingSystem
Library Collections
Library HttpLibrary.HTTP
*** Test Cases ***
Code1
#get json file
${json_data}= Get file detail.json
#get dictionaries under list
${valuelist}= Get Json Value ${json_data} /alladdress/addresslist
# display it
log to console ${valuelist}
# loop over dictionaries under list
: FOR ${key} in #{valuelist.keys()}
\ ${value}= Get From Dictionary ${valuelist} ${key}
# getting AttributeError: 'unicode' object has no attribute 'keys
\ log to console ${key},${value}
Code2
# get json file
${json_data}= Get file detail.json
# get dictionaries under list
${valuelist}= Get Json Value ${json_data} /alladdress/addresslist
# use below line to avoid unicode error
${obj_list}= evaluate json.loads('''${valuelist}''') json
# display it
log to console ${obj_list}
# loop over dictionaries under list
: FOR ${key} in #{obj_list.keys()}
\ ${value}= Get From Dictionary ${obj_list} ${key}
# getting AttributeError: 'list' object has no attribute 'keys'
\ log to console ${key},${value}
here is json file
{
"class":{
"id":0,
"name":"David"
},
"alladdress":{
"count":3,
"addresslist":[
{
"houseno":1,
"streetno":5,
"streetname":"tesla",
"city":"ABC",
"state":"AA",
"country":"UK",
"zip":85555
},
{
"houseno":2,
"streetno":6,
"streetname":"honda",
"city":"PQR",
"state":"BB",
"country":"IN",
"zip":5252
}
]
}
}
In the HttpLibrary Library there is the Parse JSON keyword that is of use here. It can convert the string of the JSON document that is fetched using Get JSON Value into a dictionary.
So the value here is that you don't have to 'walk' the dictionary to get to the node you're looking for.
*** Settings ***
Library OperatingSystem
Library HttpLibrary.HTTP
*** Test Cases ***
Fetch Address List
${json_data}= Get file details.json
${addressesJSONstring} Get Json Value ${json_data} /alladdress/addresslist
${addresseslist} Parse Json ${addressesJSONstring}
: FOR ${addressDict} in #{addresseslist}
\ log ${addressDict['country']}
It appears that the keyword Get json value is returning strings rather than objects. If you replace that call with code that uses python's json module, you can then parse the data to find what you want.
For example, this will print out each address dictionary:
*** Test Cases ***
Code1
#get json file
${json_data}= Get file detail.json
#get dictionaries under list
${data}= evaluate json.loads($json_data) json
${alladdress}= get from dictionary ${data} alladdress
${addresslist}= get from dictionary ${alladdress} addresslist
# loop over dictionaries under list
log to console addresses:
: FOR ${address} in #{addresslist}
\ log to console ${address}

http service not starting error 1009

I was trying to print a document for one of my games but the page viewer couldn't see the printer so I checked the print spooler service
C:\WINDOWS\system32>sc qc spooler
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\WINDOWS\System32\spoolsv.exe
LOAD_ORDER_GROUP : SpoolerGroup
TAG : 0
DISPLAY_NAME : Print Spooler
DEPENDENCIES : RPCSS
: http
SERVICE_START_NAME : LocalSystem
C:\WINDOWS\system32>sc query spooler
SERVICE_NAME: spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1068 (0x42c)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\WINDOWS\system32>
And tried to start it, then this happened
C:\WINDOWS\system32>net start spooler
System error 1068 has occurred.
The dependency service or group failed to start.
C:\WINDOWS\system32>
Ok so I checked the dependencies
C:\WINDOWS\system32>sc qc rpcss
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: rpcss
TYPE : 20 WIN32_SHARE_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\WINDOWS\system32\svchost.exe -k rpcss
LOAD_ORDER_GROUP : COM Infrastructure
TAG : 0
DISPLAY_NAME : Remote Procedure Call (RPC)
DEPENDENCIES : RpcEptMapper
: DcomLaunch
SERVICE_START_NAME : NT AUTHORITY\NetworkService
C:\WINDOWS\system32>sc query rpcss
SERVICE_NAME: rpcss
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\WINDOWS\system32>
Ok RPCSS is good, next one
C:\WINDOWS\system32>sc qc http && sc query http
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: http
TYPE : 1 KERNEL_DRIVER
START_TYPE : 3 DEMAND_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : system32\drivers\HTTP.sys
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : HTTP Service
DEPENDENCIES :
SERVICE_START_NAME :
SERVICE_NAME: http
TYPE : 1 KERNEL_DRIVER
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1009 (0x3f1)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\WINDOWS\system32>
OK seeing it stopped I tried to start it again
C:\WINDOWS\system32>net start http
System error 1009 has occurred.
The configuration registry database is corrupt.
C:\WINDOWS\system32>
So I run SFC to try and fix this BUT...
C:\WINDOWS\system32>sfc /scannow
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection did not find any integrity violations.
C:\WINDOWS\system32>
A fat lot of help this is, it can't even fix something so inherently wrong...
So this is where I ask the community for help, I don't know what to do past this point. Help is very much appreciated.
In my case, I had a sub-key under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters\SslBindingInfo that was missing information. i.e. all the keys such as 0.0.0.0:40015 have values like "AppId","DefaultFlags", etc.
I had one that had no values under this key. I deleted that "empty" key and HTTP was able to start up.

Robot Framework: Rest call gives "unicode object has no attribute copy" error

Below error occurring on my code
${resp}= Post Request sw3 https://sw3- test.test1.com/api/v1/test1/patients
\ ... Content-Type:application/json
\ ... Authorization:authkey02 Accept=application/json
Error as follows
KEYWORD ${resp} = RequestsLibrary . Post Request sw3, https://sw3-test.test1.com/api/v1/test1/patients, Content-Type:application/json, Authorization:authkey02, Accept=application/json
Documentation:
Send a POST request on the session object found using the
Start / End / Elapsed: 20170315 12:08:21.283 / 20170315 12:08:21.285 / 00:00:00.002
12:08:21.283 TRACE Arguments: [ 'sw3' | 'https://sw3-test.test1.com/api/v1/test1/patients' | 'Content-Type:application/json' | 'Authorization:authkey02' | 'Accept=application/json' ]
12:08:21.284 FAIL AttributeError: 'unicode' object has no attribute 'copy'
This works ok if i do not use the third line of code - what gives?
You can give it a try like passing those key:value pairs as a dictionary Header variable.
&{Header}= Content-Type:application/json Authorization:authkey02
Accept=application/json
${resp} = RequestsLibrary.Post Request sw3 https://sw3-test.test1.com/api/v1/test1/patients headers=${Header}

Custom command result

When invoking a custom command, I noticed that only the logs are displayed. For example, if my Custom Comand script contains a retrun statement return "great custom command", I can't find it in the result. Both in API Java client or shell execution cases.
What can I do to be able to retrieve that result at the end of an execution?
Thanks.
Command definition in service description file:
customCommands ([
"getText" : "getText.groovy"
])
getText.groovy file content:
def text = "great custom command"
println "trying to get a text"
return text
Assuming that you service file contains the following :
customCommands ([
"printA" : {
println "111111"
return "222222"
},
"printB" : "fileB.groovy"
])
And fileB.groovy contains the following code :
println "AAAAAA"
return "BBBBBB"
Then if you run the following command : invoke yourService printA
You will get this :
Invocation results:
1: OK from instance #1..., Result: 222222
invocation completed successfully.
and if you run the following command : invoke yourService printB
You will get this :
Invocation results:
1: OK from instance #1..., Result: AAAAAA
invocation completed successfully.
So if your custom command's implementation is a Groovy closure, then its result is its return value.
And if your custom command's implementation is an external Groovy file, then its result is its last statement output.
HTH,
Tamir.

Resources