2727from typing import Optional
2828
2929from nodescraper .base import InBandDataCollector
30- from nodescraper .connection .inband import FileArtifact
30+ from nodescraper .connection .inband import TextFileArtifact
3131from nodescraper .enums import EventCategory , EventPriority , OSFamily
3232from nodescraper .models import TaskResult
3333
@@ -60,25 +60,23 @@ def _shell_quote(self, s: str) -> str:
6060 return "'" + s .replace ("'" , "'\" '\" '" ) + "'"
6161
6262 def _nice_dmesg_name (self , path : str ) -> str :
63- """Map path to filename
64-
65- Args:
66- path (str): path of remote file
67-
68- Returns:
69- str: filename for local file
70- """
63+ """Map path to filename"""
64+ prefix = "rotated_"
7165 base = path .rstrip ("/" ).rsplit ("/" , 1 )[- 1 ]
66+
7267 if base == "dmesg" :
73- return "dmesg_log.log"
68+ return f"{ prefix } dmesg_log.log"
69+
7470 m = re .fullmatch (r"dmesg\.(\d+)\.gz" , base )
7571 if m :
76- return f"dmesg.{ m .group (1 )} .gz.log"
72+ return f"{ prefix } dmesg.{ m .group (1 )} .gz.log"
73+
7774 m = re .fullmatch (r"dmesg\.(\d+)" , base )
7875 if m :
79- return f"dmesg.{ m .group (1 )} .log"
76+ return f"{ prefix } dmesg.{ m .group (1 )} .log"
8077
81- return (base [:- 3 ] if base .endswith (".gz" ) else base ) + ".log"
78+ middle = base [:- 3 ] if base .endswith (".gz" ) else base
79+ return f"{ prefix } { middle } .log"
8280
8381 def _collect_dmesg_rotations (self ):
8482 """Collect dmesg logs"""
@@ -102,7 +100,9 @@ def _collect_dmesg_rotations(self):
102100 if res .exit_code == 0 and res .stdout is not None :
103101 fname = self ._nice_dmesg_name (p )
104102 self .logger .info ("Collected dmesg log: %s" , fname )
105- self .result .artifacts .append (FileArtifact (filename = fname , contents = res .stdout ))
103+ self .result .artifacts .append (
104+ TextFileArtifact (filename = fname , contents = res .stdout )
105+ )
106106 collected_logs .append (
107107 {"path" : p , "as" : fname , "bytes" : len (res .stdout .encode ("utf-8" , "ignore" ))}
108108 )
@@ -116,7 +116,9 @@ def _collect_dmesg_rotations(self):
116116 if res .exit_code == 0 and res .stdout is not None :
117117 fname = self ._nice_dmesg_name (p )
118118 self .logger .info ("Collected dmesg log: %s" , fname )
119- self .result .artifacts .append (FileArtifact (filename = fname , contents = res .stdout ))
119+ self .result .artifacts .append (
120+ TextFileArtifact (filename = fname , contents = res .stdout )
121+ )
120122 collected_logs .append (
121123 {"path" : p , "as" : fname , "bytes" : len (res .stdout .encode ("utf-8" , "ignore" ))}
122124 )
@@ -175,7 +177,7 @@ def collect_data(
175177 args = DmesgCollectorArgs ()
176178
177179 dmesg_content = self ._get_dmesg_content ()
178- if args .collect_logs :
180+ if args .collect_rotated_logs :
179181 self ._collect_dmesg_rotations ()
180182
181183 if dmesg_content :
0 commit comments