status.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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

# Status and Progress APIs

# Get Infocyte HUNT Jobs (Active jobs or all jobs)
function Get-ICJobs ([Switch]$All, [HashTable]$Where, [Switch]$NoLimit) {
    $url = ("$HuntServerAddress/api/jobs")
    $filter =  @{
        order = "createdOn"
        limit = $resultlimit
        skip = 0
        where = @{ and = @() }
    }

    if ($where.count -gt 0) {
        $where.GetEnumerator() | % {
            $filter['where']['and'] += @{ $($_.key) = $($_.value) }
        }
    }

    if ($All) {
        Write-Verbose "Getting All Jobs from Infocyte HUNT: $HuntServer"
    } else {
        Write-Verbose "Getting Active Jobs from Infocyte HUNT: $HuntServer"
        $filter['where']['and'] = @{ state = "active" }
    }
    _ICGetMethod -url $url -filter $filter -NoLimit:$NoLimit
}

# Get Infocyte HUNT User Audit Logs
function Get-ICUserAuditLogs ([Switch]$NoLimit, [HashTable]$Where) {
    $url = ("$HuntServerAddress/api/useractivities")
    $filter =  @{
        order = "createdOn"
        limit = $resultlimit
        skip = 0
        where = @{ and = @() }
    }
    if ($where.count -gt 0) {
        $where.GetEnumerator() | % {
            $filter['where']['and'] += @{ $($_.key) = $($_.value) }
        }
    }
        Write-Verbose "Getting User Activity Logs from Infocyte HUNT: $HuntServer"
    _ICGetMethod -url $url -filter $filter -NoLimit:$NoLimit
}

# Get Infocyte HUNT User Tasks. These are the items in the task dropdown in the UI.
function Get-ICUserTask {
    [cmdletbinding()]
    param(
        [String]$UserTaskId,
        [Switch]$Active,
        [Switch]$All,
        [HashTable]$Where,
        [Switch]$NoLimit
    )

    $filter =  @{
        order = "endedOn"
        limit = $resultlimit
        skip = 0
        where = @{ and = @() }
    }
    if ($where.count -gt 0) {
        $where.GetEnumerator() | % {
            $filter['where']['and'] += @{ $($_.key) = $($_.value) }
        }
    }

    if ($UserTaskId) {
        $url = ("$HuntServerAddress/api/usertasks/$UserTaskId")
    } else {
        if ($All) {
            Write-Verbose "Getting All User Tasks from Infocyte HUNT: $HuntServer"
            $url = ("$HuntServerAddress/api/usertasks")
        } else {
            Write-Verbose "Getting Active Tasks from Infocyte HUNT: $HuntServer"
            $url = ("$HuntServerAddress/api/usertasks/active")
        }
    }
    if ($Active) {
        Write-Verbose "Getting Running Tasks from Infocyte HUNT: $HuntServer"
        $filter['where']['and'] += @{ status = "Active" }
    }

    _ICGetMethod -url $url -filter $filter -NoLimit:$NoLimit
}

function Get-ICUserTaskItem {
    [cmdletbinding()]
    param(
        [parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [String]$UserTaskId,

        [Switch]$IncludeProgress,

        [HashTable]$Where,

        [Switch]$NoLimit
    )

    $filter =  @{
        limit = $resultlimit
        skip = 0
        order = "updatedOn"
        where = @{
            and = @( @{ userTaskId = $UserTaskId } )
        }
    }
    if ($where.count -gt 0) {
        $where.GetEnumerator() | % {
            $filter['where']['and'] += @{ $($_.key) = $($_.value) }
        }
    }

    Write-Verbose "Getting All User Task Items from Infocyte HUNT: $HuntServer"
    $url = ("$HuntServerAddress/api/userTaskItems")
    if ($IncludeProgress) {
        $items = _ICGetMethod -url $url -filter $filter -NoLimit:$NoLimit
        $items | foreach {
            if ($_.id) {
                $progress = @()
                Get-ICUserTaskItemProgress -taskItemId $_.id | foreach { $progress += "$($_.createdOn) $($_.text)" }
                $_ | Add-Member -MemberType "NoteProperty" -name "progress" -value $progress
            }
        }
        $items
    } else {
        _ICGetMethod -url $url -filter $filter -NoLimit:$NoLimit
    }
}

function Get-ICUserTaskItemProgress {
    param(
        [parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [String]$taskItemId,
        [HashTable]$Where,
        [Switch]$NoLimit
    )

    $url = ("$HuntServerAddress/api/userTaskItemProgresses")
    $filter =  @{
        order = @("createdOn desc", "id")
        limit = $resultlimit
        skip = 0
        where = @{
            and = @( @{ taskItemId = $taskItemId} )
        }
    }
    if ($where.count -gt 0) {
        $where.GetEnumerator() | % {
            $filter['where']['and'] += @{ $($_.key) = $($_.value) }
        }
    }
    _ICGetMethod -url $url -filter $filter -NoLimit:$NoLimit
}