Skip to content

Commit

Permalink
Merge pull request #69 from CentreForDigitalHumanities/feat/is-wp
Browse files Browse the repository at this point in the history
Feat/is wp
  • Loading branch information
fliepeltje authored Jun 27, 2024
2 parents 4d04f91 + d3eef1b commit 8c0b86b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions humitifier/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def host_filters(request: Request | None, all_hosts: list[Host]) -> list[Filter]
value=request.query_params.get("severity") if request else None,
fn=lambda h, p: not p.get("severity") or p.get("severity") == h.severity,
),
Filter(
typ="select",
label="Is Wordpress",
id="is_wp",
options={"true", "false"},
value=request.query_params.get("is_wp") if request else None,
fn=lambda h, p: not p.get("is_wp") or p.get("is_wp") == str(h.is_wp).lower(),
),
]


Expand Down
23 changes: 21 additions & 2 deletions humitifier/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,24 @@ def to_sql(self):
return asdict(self)


SshFact = Blocks | Groups | HostMeta | HostnameCtl | Memory | PackageList | Uptime | Users | PuppetAgentStatus
SSH_FACTS = [Blocks, Groups, HostMeta, HostnameCtl, Memory, PackageList, Uptime, Users, PuppetAgentStatus]
@ssh_command("find /hum/web/ -name 'wp-config.php' -print -quit")
@dataclass
class IsWordpress:
is_wp: bool

@classmethod
def from_stdout(cls, output: list[str]) -> "IsWordpress":
return cls(is_wp=output and output[0].strip() != "")

@classmethod
def from_sql(cls, sql_data) -> "IsWordpress":
return cls(**sql_data)

def to_sql(self):
return asdict(self)


SshFact = (
Blocks | Groups | HostMeta | HostnameCtl | Memory | PackageList | Uptime | Users | PuppetAgentStatus | IsWordpress
)
SSH_FACTS = [Blocks, Groups, HostMeta, HostnameCtl, Memory, PackageList, Uptime, Users, PuppetAgentStatus, IsWordpress]
7 changes: 7 additions & 0 deletions humitifier/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Facts:
Uptime: facts.Uptime | FactError
Users: facts.Users | FactError
PuppetAgentStatus: facts.PuppetAgentStatus | FactError
IsWordpress: facts.IsWordpress | FactError

@classmethod
def from_sql_rows(cls, rows):
Expand Down Expand Up @@ -110,6 +111,12 @@ def databases(self):
return None
return fact.databases

@property
def is_wp(self):
if isinstance(fact := self.facts.IsWordpress, FactError):
return None
return fact.is_wp

@property
def alert_codes(self):
return {a for a, _, _ in self.alerts}
Expand Down

0 comments on commit 8c0b86b

Please sign in to comment.