Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
I3csstatus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Jiří Kalvoda
I3csstatus
Commits
d8b6763d
Commit
d8b6763d
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Modules: Split http module and create http_multi module
parent
24308d1f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Module.cs
+42
-5
42 additions, 5 deletions
Module.cs
sample.conf
+26
-0
26 additions, 0 deletions
sample.conf
with
68 additions
and
5 deletions
Module.cs
+
42
−
5
View file @
d8b6763d
...
...
@@ -24,6 +24,7 @@ using System.Text.Json;
using
System.Text.Json.Nodes
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.CommandLine
;
using
System.Runtime.InteropServices
;
...
...
@@ -336,17 +337,14 @@ class ModuleExec: ModuleAbstractPipe
}
[
ModuleName
(
"http"
)]
class
ModuleHttp
:
ModuleSourceThreadAndParser
abstract
class
ModuleHttpAbstract
:
ModuleSourceThreadAndParser
{
string
url
;
HttpRequestException
error
;
InnerStatusBar
ifReadError
;
int
period_ms
;
int
timeout_ms
;
public
override
void
Init
(
ModuleParent
_bar
,
ConfigSection
section
)
{
url
=
section
.
Mandatory
(
"url"
).
AsString
();
ifReadError
=
new
InnerStatusBar
(
_bar
,
section
.
Optional
(
"error_handler"
)?.
AsConfig
()
??
new
ConfigParser
(
@"
...
...
@@ -359,6 +357,7 @@ text = ERR
base
.
Init
(
_bar
,
section
);
}
abstract
protected
Task
<
string
>
inputThreadFunc_Get
(
HttpClient
client
);
async
override
protected
void
inputThreadFunc
()
{
HttpClient
client
=
null
;
...
...
@@ -377,7 +376,7 @@ text = ERR
{
long
t
=
Environment
.
TickCount64
;
string
_data
=
await
client
.
GetStringAsync
(
url
);
string
_data
=
await
inputThreadFunc_Get
(
client
);
lock
(
this
)
{
dataTick
=
t
;
...
...
@@ -417,6 +416,44 @@ text = ERR
}
}
[
ModuleName
(
"http"
)]
class
ModuleHttp
:
ModuleHttpAbstract
{
string
url
;
public
override
void
Init
(
ModuleParent
_bar
,
ConfigSection
section
)
{
url
=
section
.
Mandatory
(
"url"
).
AsString
();
base
.
Init
(
_bar
,
section
);
}
async
override
protected
Task
<
string
>
inputThreadFunc_Get
(
HttpClient
client
)
{
return
await
client
.
GetStringAsync
(
url
);
}
}
[
ModuleName
(
"http_multi"
)]
class
ModuleHttpMulti
:
ModuleHttpAbstract
{
string
[]
urlList
;
string
separator
;
public
override
void
Init
(
ModuleParent
_bar
,
ConfigSection
section
)
{
urlList
=
section
.
Mandatory
(
"urls"
).
Lines
().
Select
(
x
=>
x
.
AsString
()).
ToArray
();
separator
=
section
.
Optional
(
"separator"
)?.
AsString
()
??
"\n"
;
base
.
Init
(
_bar
,
section
);
}
async
override
protected
Task
<
string
>
inputThreadFunc_Get
(
HttpClient
client
)
{
List
<
string
>
output
=
new
();
foreach
(
string
url
in
urlList
)
{
string
r
=
await
client
.
GetStringAsync
(
url
);
output
.
Add
(
r
);
}
return
string
.
Join
(
separator
,
output
);
}
}
[
ModuleName
(
"i3status"
)]
class
ModuleI3Status
:
Module
...
...
This diff is collapsed.
Click to expand it.
sample.conf
+
26
−
0
View file @
d8b6763d
...
...
@@ -291,6 +291,32 @@ timeout = 10
# <time> default 10
# Timeout of each HTTP request.
[
http_multi
]
# Fetch message from more than one http(s) pages
error_handler
= [
constant
]
_
color
=
red
text
=
ERR
delay
=
0
show_old
=
10
max_old
=
30
no_data_handler
= [
constant
]
text
=
No
data
parser
=
text
period
=
20
timeout
=
10
# See http module
urls
=
http
://
kam
.
mff
.
cuni
.
cz
/~
jirikalvoda
/
y
http
://
kam
.
mff
.
cuni
.
cz
/~
jirikalvoda
/
z
# mandatory <string> on each line
separator
<<
AMEN
AMEN
# <string> default see above (one new line)
# Options for all modules
# =======================
...
...
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