Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qbar
Commits
e2807646
Commit
e2807646
authored
4 years ago
by
Mr. Snow Ball / projects
Browse files
Options
Downloads
Patches
Plain Diff
Add types for Qubes events from admin.Events and admin.vm.Stats
parent
1de37c12
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/QBar/Qubes/AdminAPI.hs
+70
-2
70 additions, 2 deletions
src/QBar/Qubes/AdminAPI.hs
with
70 additions
and
2 deletions
src/QBar/Qubes/AdminAPI.hs
+
70
−
2
View file @
e2807646
...
...
@@ -7,8 +7,10 @@ import Data.Binary.Put
import
qualified
Data.ByteString
as
BS
import
qualified
Data.ByteString.Lazy
as
BL
import
qualified
Data.ByteString.Lazy.Char8
as
BLC
import
Data.Maybe
(
fromMaybe
)
import
Network.HostName
import
Pipes
import
qualified
Pipes.Prelude
as
P
import
qualified
Pipes.Safe
as
P
import
System.IO
(
Handle
,
hSetBinaryMode
)
import
System.Process.Typed
...
...
@@ -113,8 +115,74 @@ qubesAdminEvents serviceName = qubesAdminCallP serviceName >-> onlyEvents
Exception
{}
->
fail
$
"service has returned an exception: "
++
show
reply
Event
{}
->
yield
reply
qubesVMStats
::
Producer
QubesAdminReturn
(
P
.
SafeT
IO
)
()
qubesVMStats
=
qubesAdminEvents
"admin.vm.Stats"
qubesVMStatsRaw
::
Producer
QubesAdminReturn
(
P
.
SafeT
IO
)
()
qubesVMStatsRaw
=
qubesAdminEvents
"admin.vm.Stats"
data
QubesVMStats
=
QubesVMStats
{
statsVMName
::
BL
.
ByteString
,
memoryKB
::
Int
,
cpuTime
::
Int
,
cpuUsageRaw
::
Int
,
cpuUsage
::
Int
}
deriving
(
Eq
,
Ord
,
Show
,
Read
)
qubesVMStats
::
Producer
QubesVMStats
(
P
.
SafeT
IO
)
()
qubesVMStats
=
qubesVMStatsRaw
>->
P
.
mapFoldable
parse
where
parse
::
QubesAdminReturn
->
Maybe
QubesVMStats
parse
Event
{
evSubject
,
evEvent
,
evProperties
}
|
evEvent
==
"connection-established"
=
Nothing
|
evEvent
==
"vm-stats"
=
Just
$
addProperties
evProperties
$
QubesVMStats
evSubject
absent
absent
absent
absent
|
otherwise
=
Nothing
-- shouldn't happen -> report error?
parse
_
=
Nothing
-- shouldn't happen -> report error?
absent
=
(
-
1
)
readBL
=
read
.
BLC
.
unpack
addProperties
::
[(
BL
.
ByteString
,
BL
.
ByteString
)]
->
QubesVMStats
->
QubesVMStats
addProperties
((
"memory_kb"
,
x
)
:
xs
)
st
=
addProperties
xs
$
st
{
memoryKB
=
readBL
x
}
addProperties
((
"cpu_time"
,
x
)
:
xs
)
st
=
addProperties
xs
$
st
{
cpuTime
=
readBL
x
}
addProperties
((
"cpu_usage_raw"
,
x
)
:
xs
)
st
=
addProperties
xs
$
st
{
cpuUsageRaw
=
readBL
x
}
addProperties
((
"cpu_usage"
,
x
)
:
xs
)
st
=
addProperties
xs
$
st
{
cpuUsage
=
readBL
x
}
addProperties
(
_
:
xs
)
st
=
addProperties
xs
st
addProperties
[]
st
=
st
data
QubesEvent
=
OtherEvent
QubesAdminReturn
|
DomainPreStart
{
domainName
::
BL
.
ByteString
,
startGuid
::
Maybe
Bool
}
|
DomainStart
{
domainName
::
BL
.
ByteString
,
startGuid
::
Maybe
Bool
}
|
DomainUnpaused
{
domainName
::
BL
.
ByteString
}
|
DomainStopped
{
domainName
::
BL
.
ByteString
}
|
DomainShutdown
{
domainName
::
BL
.
ByteString
}
|
DomainUpdatesAvailable
{
domainName
::
BL
.
ByteString
,
updatesAvailable
::
Bool
,
updatesAvailableOld
::
Bool
}
|
DomainStartFailed
{
domainName
::
BL
.
ByteString
,
reason
::
BL
.
ByteString
}
deriving
(
Eq
,
Ord
,
Show
,
Read
)
qubesEventsRaw
::
Producer
QubesAdminReturn
(
P
.
SafeT
IO
)
()
qubesEventsRaw
=
qubesAdminEvents
"admin.Events"
qubesEvents
::
Producer
QubesEvent
(
P
.
SafeT
IO
)
()
qubesEvents
=
qubesEventsRaw
>->
P
.
mapFoldable
parse
where
parse
::
QubesAdminReturn
->
Maybe
QubesEvent
parse
Event
{
evEvent
=
"connection-established"
}
=
Nothing
parse
ev
@
(
Event
{
evSubject
,
evEvent
,
evProperties
})
=
Just
$
case
evEvent
of
"domain-pre-start"
->
DomainPreStart
evSubject
(
boolProp
"start_guid"
)
"domain-start"
->
DomainStart
evSubject
(
boolProp
"start_guid"
)
"domain-unpaused"
->
DomainUnpaused
evSubject
"domain-stopped"
->
DomainStopped
evSubject
"domain-shutdown"
->
DomainShutdown
evSubject
"domain-feature-set:updates-available"
->
DomainUpdatesAvailable
evSubject
(
boolPropViaInt
"value"
)
(
boolPropViaInt
"oldvalue"
)
"domain-start-failed"
->
DomainStartFailed
evSubject
(
fromMaybe
""
$
getProp
"reason"
)
_
->
OtherEvent
ev
where
getProp
::
BL
.
ByteString
->
Maybe
BL
.
ByteString
getProp
name
=
lookup
name
evProperties
readProp
::
Read
a
=>
BL
.
ByteString
->
Maybe
a
readProp
name
=
read
.
BLC
.
unpack
<$>
getProp
name
intProp
::
BL
.
ByteString
->
Maybe
Int
intProp
=
readProp
boolProp
::
BL
.
ByteString
->
Maybe
Bool
boolProp
=
readProp
boolPropViaInt
::
BL
.
ByteString
->
Bool
boolPropViaInt
=
fromMaybe
False
.
fmap
(
/=
0
)
.
intProp
parse
_
=
Nothing
-- shouldn't happen -> report error?
printEvents
::
Show
a
=>
Producer
a
(
P
.
SafeT
IO
)
()
->
IO
()
printEvents
prod
=
P
.
runSafeT
$
runEffect
$
prod
>->
(
forever
$
await
>>=
liftIO
.
print
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment