checkpointer.py
This module provides two kinds of checkpointer: KVStoreCheckpointer, FileCheckpointer for modular input to save checkpoint.
__all__ = ['CheckpointerException', 'KVStoreCheckpointer', 'FileCheckpointer']
module-attribute
¶
Checkpointer
¶
Base class of checkpointer.
Source code in solnlib/modular_input/checkpointer.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
batch_update(states)
abstractmethod
¶
Updates multiple documents.
Source code in solnlib/modular_input/checkpointer.py
49 50 51 |
|
delete(key)
abstractmethod
¶
Deletes document with an id that equals to key
.
Source code in solnlib/modular_input/checkpointer.py
57 58 59 |
|
get(key)
abstractmethod
¶
Gets document with an id that equals to key
.
Source code in solnlib/modular_input/checkpointer.py
53 54 55 |
|
update(key, state)
abstractmethod
¶
Updates document with an id that equals to key
and state
as
document data.
Source code in solnlib/modular_input/checkpointer.py
44 45 46 47 |
|
CheckpointerException
¶
Bases: Exception
Source code in solnlib/modular_input/checkpointer.py
37 38 |
|
FileCheckpointer
¶
Bases: Checkpointer
File checkpointer.
Use file to save modular input checkpoint.
Examples:
>>> from solnlib.modular_input import checkpointer
>>> ck = checkpointer.FileCheckpointer('/opt/splunk/var/...')
>>> ck.update(...)
>>> ck.get(...)
Source code in solnlib/modular_input/checkpointer.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
__init__(checkpoint_dir)
¶
Initializes FileCheckpointer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkpoint_dir |
str
|
Checkpoint directory. |
required |
Source code in solnlib/modular_input/checkpointer.py
218 219 220 221 222 223 224 225 226 227 228 |
|
batch_update(states)
¶
Source code in solnlib/modular_input/checkpointer.py
246 247 248 |
|
delete(key)
¶
Source code in solnlib/modular_input/checkpointer.py
258 259 260 261 262 263 |
|
encode_key(key)
¶
Source code in solnlib/modular_input/checkpointer.py
230 231 |
|
get(key)
¶
Source code in solnlib/modular_input/checkpointer.py
250 251 252 253 254 255 256 |
|
update(key, state)
¶
Source code in solnlib/modular_input/checkpointer.py
233 234 235 236 237 238 239 240 241 242 243 244 |
|
KVStoreCheckpointer
¶
Bases: Checkpointer
KVStore checkpointer.
Use KVStore to save modular input checkpoint.
More information about KV Store in Splunk is here.
Examples:
>>> from solnlib.modular_input import checkpointer
>>> checkpoint = checkpointer.KVStoreCheckpointer(
"unique_addon_checkpoints",
"session_key",
"unique_addon"
)
>>> checkpoint.update("input_1", {"timestamp": 1638043093})
>>> checkpoint.get("input_1")
>>> # returns {"timestamp": 1638043093}
Source code in solnlib/modular_input/checkpointer.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
__init__(collection_name, session_key, app, owner='nobody', scheme=None, host=None, port=None, **context)
¶
Initializes KVStoreCheckpointer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
Collection name of kvstore checkpointer. |
required |
session_key |
str
|
Splunk access token. |
required |
app |
str
|
App name of namespace. |
required |
owner |
Optional[str]
|
(optional) Owner of namespace, default is |
'nobody'
|
scheme |
Optional[str]
|
(optional) The access scheme, default is None. |
None
|
host |
Optional[str]
|
(optional) The host name, default is None. |
None
|
port |
Optional[int]
|
(optional) The port number, default is None. |
None
|
context |
Any
|
Other configurations for Splunk rest client. |
{}
|
Raises:
Type | Description |
---|---|
binding.HTTPError
|
HTTP error different from 404, for example 503 when KV Store is initializing and not ready to serve requests. |
CheckpointerException
|
If init KV Store checkpointer failed. |
Source code in solnlib/modular_input/checkpointer.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
batch_update(states)
¶
Updates multiple documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states |
Iterable[Dict[str, Any]]
|
Iterable that contains documents to update. Document should be a dict with at least “state” key. |
required |
Raises:
Type | Description |
---|---|
binding.HTTPError
|
when an error occurred in Splunk, for example, when Splunk is restarting and KV Store is not yet initialized. |
Source code in solnlib/modular_input/checkpointer.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
delete(key)
¶
Deletes document with an id that equals to key
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
|
required |
Raises:
Type | Description |
---|---|
binding.HTTPError
|
When an error occurred in Splunk (not 404 code), can be 503 code, when Splunk is restarting and KV Store is not yet initialized. |
Source code in solnlib/modular_input/checkpointer.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
get(key)
¶
Gets document with an id that equals to key
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
|
required |
Raises:
Type | Description |
---|---|
binding.HTTPError
|
When an error occurred in Splunk (not 404 code), can be 503 code, when Splunk is restarting and KV Store is not yet initialized. |
Returns:
Type | Description |
---|---|
Optional[Any]
|
Document data under |
Source code in solnlib/modular_input/checkpointer.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
update(key, state)
¶
Updates document with an id that equals to key
and state
as
document data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
|
required |
state |
Any
|
Document data to update. It can be integer, string,
or a dict, or anything that can be an argument to |
required |
Raises:
Type | Description |
---|---|
binding.HTTPError
|
when an error occurred in Splunk, for example, when Splunk is restarting and KV Store is not yet initialized. |
Source code in solnlib/modular_input/checkpointer.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|